int g_Steps = 0;
int isWaiting = 0; //0: none to wait, 1: wait for the response of "getConfigurationValue"
+pthread_mutex_t mutex_lock;
const int SUCCESS_RESPONSE = 0;
void timeCheck(int timeSec)
{
sleep(timeSec);
+ pthread_mutex_lock(&mutex_lock);
isWaiting = 0;
+ pthread_mutex_unlock(&mutex_lock);
}
void onReboot(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
{
+ pthread_mutex_lock(&mutex_lock);
isWaiting = 0;
+ pthread_mutex_unlock(&mutex_lock);
if (eCode != SUCCESS_RESPONSE)
{
void onFactoryReset(const HeaderOptions& headerOptions, const OCRepresentation& rep,
const int eCode)
{
+ pthread_mutex_lock(&mutex_lock);
isWaiting = 0;
+ pthread_mutex_unlock(&mutex_lock);
if (eCode != SUCCESS_RESPONSE)
{
void onUpdate(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
{
+ pthread_mutex_lock(&mutex_lock);
isWaiting = 0;
+ pthread_mutex_unlock(&mutex_lock);
if (eCode != SUCCESS_RESPONSE)
{
void onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
{
+ pthread_mutex_lock(&mutex_lock);
isWaiting = 0;
+ pthread_mutex_unlock(&mutex_lock);
if (eCode != SUCCESS_RESPONSE)
{
// Callback to found resources
void onFoundCandidateResource(std::vector< std::shared_ptr< OCResource > > resources)
{
-
std::string resourceURI;
std::string hostAddress;
int main(int argc, char* argv[])
{
std::string str_steps;
+ pthread_mutex_init(&mutex_lock, NULL);
//**************************************************************
// STEP 0
while (true)
{
-
+ pthread_mutex_lock(&mutex_lock);
if (isWaiting > 0)
+ {
+ pthread_mutex_unlock(&mutex_lock);
continue;
+ }
isWaiting = 0;
+ pthread_mutex_unlock(&mutex_lock);
cout << endl << endl << "(0) Quit" << std::endl;
cout << "(1) Find all resources(URI: /oic/con, /oic/diag, /factoryset)" << std::endl;
std::getline (std::cin, str_steps);
if(str_steps == "")
+ {
continue;
+ }
else
+ {
g_Steps = std::stoi(str_steps);
+ }
}
catch(std::invalid_argument&)
{
}
if (g_Steps == 0)
+ {
break;
+ }
else if (g_Steps == 1)
{
std::vector< std::string > types;
if (g_thingsmanager->getConfigurations(g_configurationCollection, configurations, &onGet)
!= OC_STACK_ERROR)
- isWaiting = 1;
+ {
+ pthread_mutex_lock(&mutex_lock);
+ isWaiting = 0;
+ pthread_mutex_unlock(&mutex_lock);
+ }
}
else if (g_Steps == 4)
{
if (g_thingsmanager->updateConfigurations(g_configurationCollection, configurations,
&onUpdate) != OC_STACK_ERROR)
- isWaiting = 1;
+ {
+ pthread_mutex_lock(&mutex_lock);
+ isWaiting = 0;
+ pthread_mutex_unlock(&mutex_lock);
+ }
}
else if (g_Steps == 5)
{
if (g_thingsmanager->factoryReset(g_diagnosticsCollection, &onFactoryReset)
!= OC_STACK_ERROR)
- isWaiting = 1;
+ {
+ pthread_mutex_lock(&mutex_lock);
+ isWaiting = 0;
+ pthread_mutex_unlock(&mutex_lock);
+ }
}
else if (g_Steps == 6)
{
}
if (g_thingsmanager->reboot(g_diagnosticsCollection, &onReboot) != OC_STACK_ERROR)
- isWaiting = 1;
+ {
+ pthread_mutex_lock(&mutex_lock);
+ isWaiting = 0;
+ pthread_mutex_unlock(&mutex_lock);
+ }
}
else if (g_Steps == 10)
{