TopicsSubscriber.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /*!
  15. * @file TopicsSubscriber.h
  16. * This header file contains the declaration of the subscriber functions.
  17. *
  18. * This file was generated by the tool fastcdrgen.
  19. */
  20. #ifndef _TOPICSAMPLE_TOPICS_SUBSCRIBER_H_
  21. #define _TOPICSAMPLE_TOPICS_SUBSCRIBER_H_
  22. #include <fastrtps/fastrtps_fwd.h>
  23. #include <fastrtps/subscriber/SubscriberListener.h>
  24. #include <fastrtps/subscriber/SampleInfo.h>
  25. #include "TopicsPubSubTypes.h"
  26. #include <QDateTime>
  27. typedef std::function<void(const char * ,const unsigned int , const unsigned int , QDateTime * ,const char *)> ModuleFun;
  28. class TopicsSubscriber
  29. {
  30. public:
  31. TopicsSubscriber();
  32. virtual ~TopicsSubscriber();
  33. bool init(const char * strtopic,const char * strpubip,const unsigned short nPort);
  34. void run();
  35. void setReceivedTopicFunction(ModuleFun xFun);
  36. private:
  37. eprosima::fastrtps::Participant *mp_participant;
  38. eprosima::fastrtps::Subscriber *mp_subscriber;
  39. char mstrtopic[256];
  40. unsigned short mnPort;
  41. class SubListener : public eprosima::fastrtps::SubscriberListener
  42. {
  43. public:
  44. SubListener() : n_matched(0),n_msg(0){};
  45. ~SubListener(){};
  46. void onSubscriptionMatched(eprosima::fastrtps::Subscriber* sub,eprosima::fastrtps::rtps::MatchingInfo& info);
  47. void onNewDataMessage(eprosima::fastrtps::Subscriber* sub);
  48. eprosima::fastrtps::SampleInfo_t m_info;
  49. int n_matched;
  50. int n_msg;
  51. void setReceivedTopicFunction(ModuleFun xFun);
  52. private:
  53. bool mbSetFun = false;
  54. ModuleFun mFun;
  55. } m_listener;
  56. TopicSample::MessagePubSubType myType;
  57. };
  58. #endif // _TOPICSAMPLE_TOPICS_SUBSCRIBER_H_