#include <iostream>
#include <thread>
class RsiSubscribeClient
{
public:
virtual void processJson() = 0;
};
class SubscribeNotification : public RsiSubscribeClient
{
public:
SubscribeNotification() : notificationId_(0){}
void subscribeToNotificationsResource()
{
std::cout<<"subscribeToNotificationsResource"<<std::endl;
processJson();
}
void processJson()
{
std::cout<<"SubscribeNotification::processJson "<<std::endl;
notificationId_ = 5436;
}
int getNotificaionId() { return notificationId_; }
private:
int notificationId_;
};
class NotificationSoundHandler : public RsiSubscribeClient
{
public:
NotificationSoundHandler()
{
std::cout<<"NotificationSoundHandler::NotificationSoundHandler"<<std::endl;
subNoti_ = std::make_shared<SubscribeNotification>();
chn_thread = std::make_shared<std::thread>(&NotificationSoundHandler::subscribeToNotificationService, this);
if(chn_thread->joinable())
chn_thread->join();
//subscribeToNotificationService();
}
void processJson()
{
std::cout<<"NotificationSoundHandler::processJson"<<std::endl;
std::shared_ptr<std::thread> noti_thread = std::make_shared<std::thread>(&SubscribeNotification::subscribeToNotificationsResource, subNoti_);
if(noti_thread->joinable()){
std::cout<<"NotificationSoundHandler::processJson join thread"<<std::endl;
noti_thread->join();
}
//subNoti_->subscribeToNotificationsResource();
std::cout<<"NotificationSoundHandler::processJson get notificationId"<<std::endl;
int notificationId = subNoti_->getNotificaionId();
std::cout<<"notificationId : " << notificationId<<std::endl;
}
void subscribeToNotificationService()
{
std::cout<<"subscribeToNotificationService"<<std::endl;
processJson();
}
private:
std::shared_ptr<std::thread> chn_thread;
std::shared_ptr<SubscribeNotification> subNoti_;
};
int main()
{
std::shared_ptr<NotificationSoundHandler> nsh = std::make_shared<NotificationSoundHandler>();
return 0;
}