fork download
  1.  
  2. #include <iostream>
  3. #include <thread>
  4.  
  5. class RsiSubscribeClient
  6. {
  7. public:
  8. virtual void processJson() = 0;
  9. };
  10.  
  11.  
  12. class SubscribeNotification : public RsiSubscribeClient
  13. {
  14. public:
  15. SubscribeNotification() : notificationId_(0){}
  16.  
  17. void subscribeToNotificationsResource()
  18. {
  19. std::cout<<"subscribeToNotificationsResource"<<std::endl;
  20. processJson();
  21. }
  22.  
  23. void processJson()
  24. {
  25. std::cout<<"SubscribeNotification::processJson "<<std::endl;
  26. notificationId_ = 5436;
  27. }
  28.  
  29. int getNotificaionId() { return notificationId_; }
  30.  
  31. private:
  32. int notificationId_;
  33. };
  34.  
  35.  
  36. class NotificationSoundHandler : public RsiSubscribeClient
  37. {
  38. public:
  39. NotificationSoundHandler()
  40. {
  41. std::cout<<"NotificationSoundHandler::NotificationSoundHandler"<<std::endl;
  42. subNoti_ = std::make_shared<SubscribeNotification>();
  43. chn_thread = std::make_shared<std::thread>(&NotificationSoundHandler::subscribeToNotificationService, this);
  44. if(chn_thread->joinable())
  45. chn_thread->join();
  46. //subscribeToNotificationService();
  47. }
  48.  
  49.  
  50. void processJson()
  51. {
  52. std::cout<<"NotificationSoundHandler::processJson"<<std::endl;
  53. std::shared_ptr<std::thread> noti_thread = std::make_shared<std::thread>(&SubscribeNotification::subscribeToNotificationsResource, subNoti_);
  54. if(noti_thread->joinable()){
  55. std::cout<<"NotificationSoundHandler::processJson join thread"<<std::endl;
  56. noti_thread->join();
  57. }
  58.  
  59. //subNoti_->subscribeToNotificationsResource();
  60.  
  61. std::cout<<"NotificationSoundHandler::processJson get notificationId"<<std::endl;
  62. int notificationId = subNoti_->getNotificaionId();
  63. std::cout<<"notificationId : " << notificationId<<std::endl;
  64. }
  65.  
  66. void subscribeToNotificationService()
  67. {
  68. std::cout<<"subscribeToNotificationService"<<std::endl;
  69. processJson();
  70. }
  71.  
  72.  
  73. private:
  74. std::shared_ptr<std::thread> chn_thread;
  75. std::shared_ptr<SubscribeNotification> subNoti_;
  76.  
  77. };
  78.  
  79. int main()
  80. {
  81. std::shared_ptr<NotificationSoundHandler> nsh = std::make_shared<NotificationSoundHandler>();
  82. return 0;
  83. }
Success #stdin #stdout 0s 84864KB
stdin
Standard input is empty
stdout
NotificationSoundHandler::NotificationSoundHandler
subscribeToNotificationService
NotificationSoundHandler::processJson
NotificationSoundHandler::processJson join thread
subscribeToNotificationsResource
SubscribeNotification::processJson 
NotificationSoundHandler::processJson get notificationId
notificationId : 5436