1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
25 #include "SSMTestApp.h"
29 SSMTestApp::SSMTestApp()
33 void SSMTestApp::displayMenu()
35 printf("===============================================\n");
36 printf(" Iotivity Soft Sensor Manager Test Application \n");
37 printf("===============================================\n");
38 printf(" 1. Register Query \n");
39 printf(" 2. Unregister Query \n");
40 printf(" 3. Register DiscomfortIndexSensor sample query \n");
41 printf(" 9. exit \n");
42 printf("===============================================\n");
43 printf(" Please Enter the NO: ");
47 void SSMTestApp::registerQuery(std::string queryString)
50 SSMRESULT rtn = SSM_E_FAIL;
52 if (queryString.size() == 0)
54 printf(" Please Enter query string: ");
56 getline(cin, queryString);
59 rtn = m_SSMClient.registerQuery(queryString, this, qid);
63 printf("The query has been registered!\n");
64 printf("QID : %d\n", qid);
67 printf("Error occured(%d)", rtn);
70 /* unRegister Query.*/
71 void SSMTestApp::unregisterQuery(void)
74 SSMRESULT rtn = SSM_E_FAIL;
76 printf(" Please Enter query string: ");
80 rtn = m_SSMClient.unregisterQuery(atoi(qid.c_str()));
83 printf("The query has been unregistered!\n");
85 printf("Error occured(%d)\n", (int) rtn);
88 /* APP. Level Callback Function for Observer of client. */
89 SSMRESULT SSMTestApp::onQueryEngineEvent(int cqid, IDataReader *pResult)
92 IModelData *pModelData = NULL;
93 std::vector<std::string> affectedModels;
95 cout << "Event received! cqid = " << cqid << endl;
97 pResult->getAffectedModels(&affectedModels);
99 for (std::vector<std::string>::iterator itor = affectedModels.begin();
100 itor != affectedModels.end(); ++itor)
102 cout << "Printing " << *itor << " model" << endl;
103 pResult->getModelDataCount(*itor, &dataCount);
104 for (int i = 0; i < dataCount; i++)
106 pResult->getModelData(*itor, i, &pModelData);
107 cout << "dataId: " << pModelData->getDataId() << endl;
108 for (int j = 0; j < pModelData->getPropertyCount(); j++)
110 cout << "Type: " << pModelData->getPropertyName(j) << " Value: " << pModelData->getPropertyValue(
120 * APP. Main Function.
124 printf("program start.\n");
125 printf("searching SSMResource\n");
126 SSMTestApp *SSMApp = new SSMTestApp();
127 APPMenu::APPMenu menu = APPMenu::NONE;
129 while (menu != APPMenu::EXIT)
131 SSMApp->displayMenu();
133 menu = (APPMenu::APPMenu) (getchar() - '0');
134 if ((APPMenu::APPMenu) 0 > menu || menu > APPMenu::EXIT)
135 menu = (APPMenu::APPMenu) (getchar() - '0');
139 case APPMenu::REGISTER:
140 std::cout << "register operate." << std::endl;
141 SSMApp->registerQuery("");
144 case APPMenu::UNREGISTER:
145 std::cout << "unregister operate." << std::endl;
146 SSMApp->unregisterQuery();
149 case APPMenu::DISCOMFORT_SAMPLE:
150 SSMApp->registerQuery("subscribe Device.DiscomfortIndexSensor "\
151 "if Device.DiscomfortIndexSensor.discomfortIndex > 0");
155 std::cout << "program exit." << std::endl;
159 std::cout << "Not supported yet." << std::endl;