UnityServiceProvider.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. © Dyno Robotics, 2018
  3. Author: Samuel Lindgren (samuel@dynorobotics.se)
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. <http://www.apache.org/licenses/LICENSE-2.0>.
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. using UnityEngine;
  15. namespace RosSharp.RosBridgeClient
  16. {
  17. [RequireComponent(typeof(RosConnector))]
  18. public abstract class UnityServiceProvider<Tin, Tout> : MonoBehaviour where Tin : Message where Tout : Message
  19. {
  20. public string ServiceName;
  21. protected virtual void Start()
  22. {
  23. GetComponent<RosConnector>().RosSocket.AdvertiseService<Tin, Tout>(ServiceName, ServiceCallHandler);
  24. }
  25. protected abstract bool ServiceCallHandler(Tin request, out Tout response);
  26. }
  27. }