TopicsSubscriber.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 = 0,const unsigned short nPort = 5100,int ntype = 0);
  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. class SubListener : public eprosima::fastrtps::SubscriberListener
  41. {
  42. public:
  43. SubListener() : n_matched(0),n_msg(0){};
  44. ~SubListener(){};
  45. void onSubscriptionMatched(eprosima::fastrtps::Subscriber* sub,eprosima::fastrtps::rtps::MatchingInfo& info);
  46. void onNewDataMessage(eprosima::fastrtps::Subscriber* sub);
  47. eprosima::fastrtps::SampleInfo_t m_info;
  48. int n_matched;
  49. int n_msg;
  50. void setReceivedTopicFunction(ModuleFun xFun);
  51. private:
  52. bool mbSetFun = false;
  53. ModuleFun mFun;
  54. } m_listener;
  55. TopicSample::MessagePubSubType myType;
  56. };
  57. #endif // _TOPICSAMPLE_TOPICS_SUBSCRIBER_H_