1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 #if defined(__linux__)
25 #include "RCSResourceContainer.h"
26 #include "RCSBundleInfo.h"
27 #include "oc_logger.hpp"
31 using namespace OIC::Service;
32 using OC::oc_log_stream;
36 /* Annother way to create a context: */
37 auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
39 static OC::oc_log_stream ols(oc_make_ostream_logger);
40 static boost::iostreams::stream<OC::oc_log_stream> os(ols);
45 void getCurrentPath(std::string *pPath)
47 char buffer[MAX_PATH];
49 #if defined(__linux__)
51 int length = readlink("/proc/self/exe", buffer, MAX_PATH - 1);
55 buffer[length] = '\0';
56 strPath = strrchr(buffer, '/');
62 pPath->append(buffer);
67 info_logger()->set_module("ContainerTest");
68 info_logger()->set_level(OC_LOG_INFO);
70 info_logger() << "Starting container test." << std::flush;
72 std::string strConfigPath;
73 getCurrentPath(&strConfigPath);
74 strConfigPath.append("/examples/ResourceContainerConfig.xml");
76 RCSResourceContainer *container = RCSResourceContainer::getInstance();
77 container->startContainer(strConfigPath);
79 /*so bundle add test*/
80 cout << "++++++++++++++++++++++++++" << endl;
81 cout << "+++ Test for SO Bundle +++" << endl;
82 cout << "++++++++++++++++++++++++++" << endl;
83 cout << "Press enter to add SO bundle " << endl;
85 std::map<string, string> bundleParams;
86 container->addBundle("oic.bundle.hueSample", "", "libHueBundle.so", "huesample", bundleParams);
88 std::list<unique_ptr<RCSBundleInfo>> bundles = container->listBundles();
89 std::list<unique_ptr<RCSBundleInfo>>::iterator bundleIt;
91 cout << "\t>>> bundle list size : " << bundles.size() << endl;
92 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
94 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
97 cout << "\nPress enter to start SO bundle " << endl;
99 container->startBundle("oic.bundle.hueSample");
101 std::map<string, string> resourceParams;
102 cout << "Press enter to add SO bundle resource " << endl;
104 resourceParams["resourceType"] = "oic.r.light";
105 resourceParams["address"] = "http://192.168.0.2/api/newdeveloper/lights/1";
106 container->addResourceConfig("oic.bundle.hueSample", "", resourceParams);
107 container->addResourceConfig("oic.bundle.hueSample", "", resourceParams);
109 std::list<string> resources = container->listBundleResources("oic.bundle.hueSample");
110 std::list<string>::iterator resourceIt;
111 cout << "\t>>> resource list size : " << resources.size() << endl;
112 for (resourceIt = resources.begin(); resourceIt != resources.end(); resourceIt++)
114 cout << "\t>>> resource uri : " << (*resourceIt).c_str() << endl;
117 cout << "\nPress enter to remove SO bundle resource " << endl;
119 container->removeResourceConfig("oic.bundle.hueSample", "/hue/light/1");
121 resources = container->listBundleResources("oic.bundle.hueSample");
122 cout << "\t>>> resource list size : " << resources.size() << endl;
123 for (resourceIt = resources.begin(); resourceIt != resources.end(); resourceIt++)
125 cout << "\t>>> resource uri : " << (*resourceIt).c_str() << endl;
128 cout << "\nPress enter to stop SO Bundle " << endl;
130 container->stopBundle("oic.bundle.hueSample");
132 cout << "Press enter to test remove SO Bundle " << endl;
134 container->removeBundle("oic.bundle.hueSample");
136 bundles = container->listBundles();
137 cout << "\t>>> bundle list size : " << bundles.size() << endl;
138 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
140 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
144 /*java bundle add test*/
145 cout << "\n++++++++++++++++++++++++++++" << endl;
146 cout << "+++ Test for JAVA Bundle +++" << endl;
147 cout << "++++++++++++++++++++++++++++" << endl;
148 cout << "Press enter to add java bundle " << endl;
150 bundleParams["libraryPath"] = ".";
151 std::string activator = "org.iotivity.bundle.hue.HueBundleActivator";
152 container->addBundle("oic.bundle.hueJavaSample2", "/hueJava",
153 "../../../../../../service/resource-container/" \
154 "examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar",
158 bundles = container->listBundles();
159 cout << "\t>>> bundle list size : " << bundles.size() << endl;
160 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
162 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
165 cout << "\nPress enter to start java bundle " << endl;
167 container->startBundle("oic.bundle.hueJavaSample2");
169 cout << "Press enter to stop java Bundle " << endl;
171 container->stopBundle("oic.bundle.hueJavaSample2");
173 cout << "Press enter to test remove java Bundle " << endl;
175 container->removeBundle("oic.bundle.hueJavaSample2");
177 bundles = container->listBundles();
178 cout << "\t>>> bundle list size : " << bundles.size() << endl;
179 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
181 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
185 cout << "\nPress enter to stop container " << endl;
187 container->stopContainer();
189 cout << "Container stopped. Bye" << endl;