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 ******************************************************************/
26 #include "SSMTestApp.h"
30 SSMTestApp::SSMTestApp()
34 void SSMTestApp::displayMenu()
36 printf("===============================================\n");
37 printf(" Iotivity Soft Sensor Manager Test Application \n");
38 printf("===============================================\n");
39 printf(" 1. Register Query \n");
40 printf(" 2. Unregister Query \n");
41 printf(" 3. Register DiscomfortIndexSensor sample query \n");
42 printf(" 4. Register IndoorTrajectorySensor sample query \n");
43 printf(" 5. Register BMISensor sample query \n");
44 printf(" 9. exit \n");
45 printf("===============================================\n");
46 printf(" Please Enter the NO: ");
50 void SSMTestApp::registerQuery(std::string queryString)
53 SSMRESULT rtn = SSM_E_FAIL;
55 if (queryString.size() == 0)
57 printf(" Please Enter query string: ");
58 getline(cin, queryString);
61 rtn = RegisterQuery(queryString, this, qid);
65 printf("The query has been registered!\n");
66 printf("QID : %d\n", qid);
69 printf("Error occured(%d)\n", rtn);
72 /* unRegister Query.*/
73 void SSMTestApp::unregisterQuery(void)
76 SSMRESULT rtn = SSM_E_FAIL;
78 printf(" Please Enter query Id: ");
81 rtn = UnregisterQuery(atoi(qid.c_str()));
84 printf("The query has been unregistered!\n");
86 printf("Error occured(%d)\n", (int) rtn);
91 char input_name[INPUT_EA][10] = { "trackeeID", "timeT0", "ref01T0", "ref02T0", "ref03T0", "timeT1", "ref01T1", "ref02T1", "ref03T1" };
93 void SSMTestApp::TrajectoryDataOutput(IModelData *pModelData)
95 std::string name = "";
98 std::string trackeeID;
99 std::string T0DateTime;
103 std::string T1DateTime;
108 for (int j = 0; j < pModelData->getPropertyCount(); j++)
110 name = pModelData->getPropertyName(j);
112 for (l = 0; l < INPUT_EA; l++)
114 if (name.compare(input_name[l]) == 0)
121 trackeeID = pModelData->getPropertyValue(j);
124 T0DateTime = pModelData->getPropertyValue(j);
127 T0Ref01 = pModelData->getPropertyValue(j);
130 T0Ref02 = pModelData->getPropertyValue(j);
133 T0Ref03 = pModelData->getPropertyValue(j);
136 T1DateTime = pModelData->getPropertyValue(j);
139 T1Ref01 = pModelData->getPropertyValue(j);
142 T1Ref02 = pModelData->getPropertyValue(j);
145 T1Ref03 = pModelData->getPropertyValue(j);
152 printf("===========================================\n");
153 printf(" ITS Trajectory Data Output \n");
154 printf("===========================================\n");
156 printf(" < Trackee Thing ID : %s > \n", trackeeID.c_str());
157 printf(" - Trajectory 01 \n");
158 printf(" 0. Date, Time : %s \n", T0DateTime.c_str());
159 printf(" 1. Ref. Thing : %s \n", T0Ref01.c_str());
160 printf(" 2. Ref. Thing : %s \n", T0Ref02.c_str());
161 printf(" 3. Ref. Thing : %s \n", T0Ref03.c_str());
163 printf(" - Trajectory 02 \n");
164 printf(" 0. Date, Time : %s \n", T1DateTime.c_str());
165 printf(" 1. Ref. Thing : %s \n", T1Ref01.c_str());
166 printf(" 2. Ref. Thing : %s \n", T1Ref02.c_str());
167 printf(" 3. Ref. Thing : %s \n", T1Ref03.c_str());
169 printf("===========================================\n");
172 /* APP. Level Callback Function for Observer of client. */
173 SSMRESULT SSMTestApp::onQueryEngineEvent(int cqid, IDataReader *pResult)
176 IModelData *pModelData = NULL;
177 std::vector<std::string> affectedModels;
179 cout << "Event received! cqid = " << cqid << endl;
181 pResult->getAffectedModels(&affectedModels);
183 for (std::vector<std::string>::iterator itor = affectedModels.begin();
184 itor != affectedModels.end(); ++itor)
186 cout << "Printing " << *itor << " model" << endl;
187 pResult->getModelDataCount(*itor, &dataCount);
188 for (int i = 0; i < dataCount; i++)
190 pResult->getModelData(*itor, i, &pModelData);
191 cout << "dataId: " << pModelData->getDataId() << endl;
192 for (int j = 0; j < pModelData->getPropertyCount(); j++)
194 cout << "Type: " << pModelData->getPropertyName(j) << " Value: " << pModelData->getPropertyValue(
198 //TrajectoryDataOutput(pModelData);
206 * APP. Main Function.
210 printf("program start.\n");
211 printf("searching SSMResource\n");
212 SSMTestApp *SSMApp = new SSMTestApp();
213 APPMenu::APPMenu menu = APPMenu::NONE;
216 std::string xmlDescription = "<SSMCore>"
218 "<UDN>abcde123-31f8-11b4-a222-08002b34c003</UDN>"
224 if (InitializeSSM(xmlDescription) != SSM_S_OK)
225 std::cout << "core init failed" << std::endl;
227 while (menu != APPMenu::EXIT)
229 SSMApp->displayMenu();
231 getline(cin, strMenu);
232 menu = (APPMenu::APPMenu) (atoi(strMenu.c_str()));
236 case APPMenu::REGISTER:
237 std::cout << "register operate." << std::endl;
238 SSMApp->registerQuery("");
241 case APPMenu::UNREGISTER:
242 std::cout << "unregister operate." << std::endl;
243 SSMApp->unregisterQuery();
246 case APPMenu::DISCOMFORT_SAMPLE:
247 SSMApp->registerQuery("subscribe Device.DiscomfortIndexSensor "\
248 "if Device.DiscomfortIndexSensor.discomfortIndex > 0");
251 case APPMenu::ITS_SAMPLE:
252 SSMApp->registerQuery("subscribe Device.IndoorTrajectorySensor "\
253 "if Device.IndoorTrajectorySensor.trackeeID == \"9059AF16FEF7\"");
256 case APPMenu::BMI_SAMPLE:
257 SSMApp->registerQuery("subscribe Device.BMISensor "\
258 "if Device.BMISensor.BMIresult > 0");
267 std::cout << "program exit." << std::endl;
271 std::cout << "Not supported yet." << std::endl;