1 /******************************************************************
3 * Copyright 2015 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 ******************************************************************/
21 #include "container.h"
24 #include "RCSResourceContainer.h"
30 using namespace OIC::Service;
32 # define checkContainer NULL!=container?true:false
34 RCSResourceContainer *container;
35 static bool s_containerFlag = false;
36 static bool s_hueBundleFlag = false;
37 static bool s_bmiBundleFlag = false;
39 static Evas_Object *log_entry = NULL;
40 static Evas_Object *listnew = NULL;
41 static Evas_Object *naviframe = NULL;
43 // Function to update the log in UI
44 void *updateContainerLog(void *data)
46 string *log = (string *)data;
48 elm_entry_entry_append(log_entry, (*log).c_str());
49 elm_entry_cursor_end_set(log_entry);
53 static void list_selected_cb(void *data, Evas_Object *obj, void *event_info)
55 Elm_Object_Item *it = (Elm_Object_Item *)event_info;
56 elm_list_item_selected_set(it, EINA_FALSE);
59 static void onDestroy()
64 static void listBundles(void *data, Evas_Object *obj, void *event_info)
66 dlog_print(DLOG_INFO, LOG_TAG, "#### listBundles starting");
67 string logMessage = "";
71 std::list<unique_ptr<RCSBundleInfo>> bundles = container->listBundles();
72 std::list<unique_ptr<RCSBundleInfo>>::iterator bundleIt;
73 logMessage += "Bundle List Size : " + to_string(bundles.size()) + "<br>";
75 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
77 string bundleString((*bundleIt)->getID().c_str());
78 logMessage += "Bundle ID : " + bundleString + "<br>";
83 logMessage = "NO CONTAINER <br>";
86 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
87 logMessage += "----------------------<br>";
88 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
91 dlog_print(DLOG_INFO, LOG_TAG, "#### listBundles exit");
94 static void listHueResources(void *data, Evas_Object *obj, void *event_info)
96 dlog_print(DLOG_INFO, LOG_TAG, "#### listHueResources starting");
97 string logMessage = "";
101 std::list<string> resources = container->listBundleResources("oic.bundle.hueSample");
102 std::list<string>::iterator resourceIt;
103 logMessage += "Resource Bundle Size : " + to_string(resources.size()) + "<br>";
104 for (resourceIt = resources.begin(); resourceIt != resources.end(); resourceIt++)
106 string resourceString((*resourceIt).c_str());
107 logMessage += "Resource URI : " + resourceString + "<br>";
112 logMessage = "NO CONTAINER <br>";
115 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
116 logMessage += "----------------------<br>";
117 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
120 dlog_print(DLOG_INFO, LOG_TAG, "#### listHueResources exit");
123 static void listBMIResources(void *data, Evas_Object *obj, void *event_info)
125 dlog_print(DLOG_INFO, LOG_TAG, "#### listBMIResources starting");
126 string logMessage = "";
132 std::list<string> resources = container->listBundleResources("oic.bundle.BMISensor");
133 std::list<string>::iterator resourceIt;
134 logMessage += "Resource Bundle Size : " + to_string(resources.size()) + "<br>";
135 for (resourceIt = resources.begin(); resourceIt != resources.end(); resourceIt++)
137 string resourceString((*resourceIt).c_str());
138 logMessage += "Resource URI : " + resourceString + "<br>";
143 logMessage = "FIRST ADD AND START BMI BUNDLE <br>";
149 logMessage = "NO CONTAINER <br>";
152 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
153 logMessage += "----------------------<br>";
154 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
157 dlog_print(DLOG_INFO, LOG_TAG, "#### listBMIResources exit");
160 static void addHueResourceConfig(void *data, Evas_Object *obj, void *event_info)
162 dlog_print(DLOG_INFO, LOG_TAG, "#### addHueResourceConfig starting");
163 string logMessage = "";
167 std::map<string, string> resourceParams;
168 resourceParams["resourceType"] = "oic.r.light";
169 resourceParams["address"] = "http://192.168.0.2/api/newdeveloper/lights/1";
172 container->addResourceConfig("oic.bundle.hueSample", "", resourceParams);
173 logMessage += "1 Light Resource added<br>";
174 listHueResources(NULL, NULL, NULL);
178 logMessage += "HUE BUNDLE NOT FOUND<br>";
183 logMessage = "NO CONTAINER <br>";
186 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
187 logMessage += "----------------------<br>";
188 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
191 dlog_print(DLOG_INFO, LOG_TAG, "#### addHueResourceConfig exit");
194 static void addBMIResourceConfig(void *data, Evas_Object *obj, void *event_info)
196 dlog_print(DLOG_INFO, LOG_TAG, "#### addBMIResourceConfig starting");
197 string logMessage = "";
201 std::map<string, string> resourceParams;
202 resourceParams["resourceType"] = "oic.softsensor";
205 container->addResourceConfig("oic.bundle.BMISensor", "", resourceParams);
206 logMessage += "Resource added<br>";
207 listBMIResources(NULL, NULL, NULL);
211 logMessage += "BMI BUNDLE NOT FOUND<br>";
217 logMessage = "NO CONTAINER <br>";
220 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
221 logMessage += "----------------------<br>";
222 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
225 dlog_print(DLOG_INFO, LOG_TAG, "#### addBMIResourceConfig exit");
228 static void removeHueResourceConfig(void *data, Evas_Object *obj, void *event_info)
230 dlog_print(DLOG_INFO, LOG_TAG, "#### removeHueResourceConfig starting");
231 string logMessage = "";
235 std::list<string> resources = container->listBundleResources("oic.bundle.hueSample");
236 std::list<string>::iterator resourceIt;
237 if (!resources.size())
239 logMessage += "No Resource to remove <br>";
243 resourceIt = resources.begin();
244 string resourceString((*resourceIt).c_str());
247 container->removeResourceConfig("oic.bundle.hueSample", resourceString);
248 logMessage += "Resource removed <br>";
249 listHueResources(NULL, NULL, NULL);
253 logMessage += "HUE BUNDLE NOT FOUND<br>";
256 listHueResources(NULL, NULL, NULL);
260 logMessage = "NO CONTAINER <br>";
263 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
264 logMessage += "----------------------<br>";
265 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
268 dlog_print(DLOG_INFO, LOG_TAG, "#### removeHueResourceConfig exit");
271 static void removeBMIResourceConfig(void *data, Evas_Object *obj, void *event_info)
273 dlog_print(DLOG_INFO, LOG_TAG, "#### removeBMIResourceConfig starting");
274 string logMessage = "";
278 std::list<string> resources = container->listBundleResources("oic.bundle.BMISensor");
279 std::list<string>::iterator resourceIt;
280 if (!resources.size())
282 logMessage += "No Resource to remove <br>";
286 resourceIt = resources.begin();
287 string resourceString((*resourceIt).c_str());
290 container->removeResourceConfig("oic.bundle.BMISensor", resourceString);
291 logMessage += "Resource removed <br>";
292 listBMIResources(NULL, NULL, NULL);
296 logMessage += "BMI BUNDLE NOT FOUND<br>";
299 listHueResources(NULL, NULL, NULL);
303 logMessage = "NO CONTAINER <br>";
306 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
307 logMessage += "----------------------<br>";
308 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
311 dlog_print(DLOG_INFO, LOG_TAG, "#### removeBMIResourceConfig exit");
314 static void addHueBundle(void *data, Evas_Object *obj, void *event_info)
316 dlog_print(DLOG_INFO, LOG_TAG, "#### addHUEBundle starting");
318 string logMessage = "";
322 std::map<string, string> bundleParams;
323 container->addBundle("oic.bundle.hueSample", "",
324 "/opt/usr/apps/org.tizen.containerserver/lib/libHueBundle.so",
325 "huesample", bundleParams);
326 logMessage += "HUE Bundle added <br>";
330 logMessage = "NO CONTAINER <br>";
333 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
334 logMessage += "----------------------<br>";
335 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
338 dlog_print(DLOG_INFO, LOG_TAG, "#### addHUEBundle exit");
341 static void addBMIBundle(void *data, Evas_Object *obj, void *event_info)
343 dlog_print(DLOG_INFO, LOG_TAG, "#### addBMIBundle starting");
345 string logMessage = "";
349 std::map<string, string> bundleParams;
350 container->addBundle("oic.bundle.BMISensor", "",
351 "/opt/usr/apps/org.tizen.containerserver/lib/libBMISensorBundle.so",
352 "bmisensor", bundleParams);
353 logMessage += "BMI Bundle added <br>";
357 logMessage = "NO CONTAINER <br>";
360 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
361 logMessage += "----------------------<br>";
362 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
365 dlog_print(DLOG_INFO, LOG_TAG, "#### addBMIBundle exit");
368 static void removeHueBundle(void *data, Evas_Object *obj, void *event_info)
370 dlog_print(DLOG_INFO, LOG_TAG, "#### removeHUEBundle starting");
371 string logMessage = "";
375 container->removeBundle("oic.bundle.hueSample");
376 logMessage += "BMI Bundle removed <br>";
377 s_hueBundleFlag = false;
381 logMessage = "NO CONTAINER <br>";
384 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
385 logMessage += "----------------------<br>";
386 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
389 dlog_print(DLOG_INFO, LOG_TAG, "#### removeHUEBundle exit");
392 static void removeBMIBundle(void *data, Evas_Object *obj, void *event_info)
394 dlog_print(DLOG_INFO, LOG_TAG, "#### removeBMIBundle starting");
395 string logMessage = "";
399 container->removeBundle("oic.bundle.BMISensor");
400 logMessage += "BMI Bundle removed <br>";
401 s_hueBundleFlag = false;
405 logMessage = "NO CONTAINER <br>";
408 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
409 logMessage += "----------------------<br>";
410 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
413 dlog_print(DLOG_INFO, LOG_TAG, "#### removeBMIBundle exit");
416 static void startHueBundle(void *data, Evas_Object *obj, void *event_info)
418 dlog_print(DLOG_INFO, LOG_TAG, "#### startHUEBundle starting");
419 string logMessage = "";
423 container->startBundle("oic.bundle.hueSample");
424 logMessage += "HUE Bundle started <br>";
425 s_hueBundleFlag = true;
429 logMessage = "NO CONTAINER <br>";
432 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
433 logMessage += "----------------------<br>";
434 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
437 dlog_print(DLOG_INFO, LOG_TAG, "#### startHUEBundle exit");
440 static void startBMIBundle(void *data, Evas_Object *obj, void *event_info)
442 dlog_print(DLOG_INFO, LOG_TAG, "#### startBMIBundle starting");
443 string logMessage = "";
447 container->startBundle("oic.bundle.BMISensor");
448 logMessage += "BMI Bundle started <br>";
449 s_bmiBundleFlag = true;
453 logMessage = "NO CONTAINER <br>";
456 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
457 logMessage += "----------------------<br>";
458 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
461 dlog_print(DLOG_INFO, LOG_TAG, "#### startBMIBundle exit");
464 static void stopHueBundle(void *data, Evas_Object *obj, void *event_info)
466 dlog_print(DLOG_INFO, LOG_TAG, "#### stopHUEBundle starting");
467 string logMessage = "";
471 container->stopBundle("oic.bundle.hueSample");
472 logMessage += "HUE Bundle stopped <br>";
473 s_hueBundleFlag = false;
477 logMessage = "NO CONTAINER <br>";
480 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
481 logMessage += "----------------------<br>";
482 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
485 dlog_print(DLOG_INFO, LOG_TAG, "#### stopHUEBundle exit");
488 static void stopBMIBundle(void *data, Evas_Object *obj, void *event_info)
490 dlog_print(DLOG_INFO, LOG_TAG, "#### stopBMIBundle starting");
491 string logMessage = "";
495 container->stopBundle("oic.bundle.BMISensor");
496 logMessage += "BMI Bundle stopped <br>";
497 s_bmiBundleFlag = false;
501 logMessage = "NO CONTAINER <br>";
504 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
505 logMessage += "----------------------<br>";
506 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
509 dlog_print(DLOG_INFO, LOG_TAG, "#### stopBMIBundle exit");
512 void *showContainerAPIs(void *data)
514 // Add items to the list only if the list is empty
515 const Eina_List *eina_list = elm_list_items_get(listnew);
516 int count = eina_list_count(eina_list);
519 elm_list_item_append(listnew, "1. List Bundles", NULL, NULL,
522 elm_list_item_append(listnew, "2. List Hue resources", NULL, NULL,
523 listHueResources, NULL);
525 elm_list_item_append(listnew, "3. Add HUE Bundle Resource", NULL, NULL,
526 addHueResourceConfig, NULL);
528 elm_list_item_append(listnew, "4. Remove HUE Bundle Resource", NULL, NULL,
529 removeHueResourceConfig, NULL);
531 elm_list_item_append(listnew, "5. Add BMI Bundle", NULL, NULL,
534 elm_list_item_append(listnew, "6. Start BMI Bundle", NULL, NULL,
535 startBMIBundle, NULL);
537 elm_list_item_append(listnew, "7. Remove BMI Bundle", NULL, NULL,
538 removeBMIBundle, NULL);
540 elm_list_item_append(listnew, "8. Stop BMI Bundle", NULL, NULL,
541 stopBMIBundle, NULL);
543 elm_list_go(listnew);
548 // Method to be called when the start container UI Button is selected
549 static void startContainer(void *data, Evas_Object *obj, void *event_info)
551 std::string xmlDescription =
552 "/opt/usr/apps/org.tizen.containerserver/lib/ResourceContainerConfig.xml";
553 string logMessage = "";
557 dlog_print(DLOG_INFO, LOG_TAG, "#### Container starting");
558 container = RCSResourceContainer::getInstance();
560 if (!s_containerFlag)
562 container->startContainer(xmlDescription);
563 s_containerFlag = true;
564 s_hueBundleFlag = true;
565 logMessage += "CONTAINER STARTED<br>";
566 logMessage += "ADD AND START BUNDLES<br>";
570 logMessage += "ALREADY STARTED<br>";
575 dlog_print(DLOG_ERROR, LOG_TAG, "list is NULL - So unable to add items!!!");
578 // Show the UI list of group APIs
579 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))showContainerAPIs, NULL);
581 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
582 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
586 // Method to be called when the stop container UI Button is selected
587 static void stopContainer(void *data, Evas_Object *obj, void *event_info)
589 string logMessage = "";
591 dlog_print(DLOG_INFO, LOG_TAG, "#### Container stopped");
595 s_containerFlag = false;
596 removeHueBundle(NULL, NULL, NULL);
597 stopHueBundle(NULL, NULL, NULL);
599 container->stopContainer();
600 logMessage += "CONTAINER STOPPED<br>";
605 logMessage += "NO CONTAINER <br>";
608 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
609 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateContainerLog,
614 naviframe_pop_cb(void *data, Elm_Object_Item *it)
618 if (NULL != log_entry)
620 evas_object_del(log_entry);
625 evas_object_del(listnew);
631 // Method to set up server screens
632 void containerCreateUI(void *data, Evas_Object *obj, void *event_info)
634 dlog_print(DLOG_INFO, LOG_TAG, "#### container UI");
635 s_containerFlag = false;
636 s_hueBundleFlag = false;
638 Evas_Object *scroller;
639 Evas_Object *nf = (Evas_Object *)data;
640 Evas_Object *start_button;
641 Evas_Object *stop_button;
642 Elm_Object_Item *nf_it;
646 scroller = elm_scroller_add(nf);
647 elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
648 elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
649 dlog_print(DLOG_INFO, LOG_TAG, "#### container UI 1");
652 layout = elm_layout_add(nf);
653 elm_layout_file_set(layout, ELM_DEMO_EDJ, "container_layout");
654 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
656 elm_object_content_set(scroller, layout);
657 dlog_print(DLOG_INFO, LOG_TAG, "#### container UI 2");
660 start_button = elm_button_add(layout);
661 elm_object_part_content_set(layout, "start_button", start_button);
662 elm_object_text_set(start_button, "Start Container");
663 evas_object_smart_callback_add(start_button, "clicked", startContainer, NULL);
664 dlog_print(DLOG_INFO, LOG_TAG, "#### container UI 3");
667 stop_button = elm_button_add(layout);
668 elm_object_part_content_set(layout, "stop_button", stop_button);
669 elm_object_text_set(stop_button, "Stop Container");
670 evas_object_smart_callback_add(stop_button, "clicked", stopContainer, NULL);
671 dlog_print(DLOG_INFO, LOG_TAG, "#### container UI 4");
674 listnew = elm_list_add(layout);
675 elm_list_mode_set(listnew, ELM_LIST_COMPRESS);
676 evas_object_smart_callback_add(listnew, "selected", list_selected_cb, NULL);
677 elm_object_part_content_set(layout, "listnew", listnew);
678 elm_list_go(listnew);
679 dlog_print(DLOG_INFO, LOG_TAG, "#### container UI 5");
681 // log_entry - text area for log
682 log_entry = elm_entry_add(layout);
683 elm_entry_scrollable_set(log_entry, EINA_TRUE);
684 elm_entry_editable_set(log_entry, EINA_FALSE);
685 elm_object_part_text_set(log_entry, "elm.guide", "Logs will be updated here!!!");
686 evas_object_size_hint_weight_set(log_entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
687 evas_object_size_hint_align_set(log_entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
688 elm_object_part_content_set(layout, "log", log_entry);
690 nf_it = elm_naviframe_item_push(nf, "Resource Container", NULL, NULL, scroller, NULL);
691 elm_naviframe_item_pop_cb_set(nf_it, naviframe_pop_cb, NULL);
692 dlog_print(DLOG_INFO, LOG_TAG, "#### container UI 6");