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 /* Another 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);
44 void getCurrentPath(std::string *pPath)
46 char buffer[MAX_PATH];
48 #if defined(__linux__)
50 int length = readlink("/proc/self/exe", buffer, MAX_PATH - 1);
54 buffer[length] = '\0';
55 strPath = strrchr(buffer, '/');
61 pPath->append(buffer);
66 info_logger()->set_module("ContainerTest");
67 info_logger()->set_level(OC_LOG_INFO);
69 info_logger() << "Starting container test." << std::flush;
71 std::string strConfigPath;
72 getCurrentPath(&strConfigPath);
73 strConfigPath.append("/examples/ResourceContainerConfig.xml");
75 RCSResourceContainer *container = RCSResourceContainer::getInstance();
76 container->startContainer(strConfigPath);
78 /*so bundle add test*/
79 cout << "++++++++++++++++++++++++++" << endl;
80 cout << "+++ Test for SO Bundle +++" << endl;
81 cout << "++++++++++++++++++++++++++" << endl;
82 cout << "Press enter to add SO bundle " << endl;
84 std::map<string, string> bundleParams;
85 container->addBundle("oic.bundle.hueSample", "", "libHueBundle.so", "huesample", bundleParams);
87 std::list<unique_ptr<RCSBundleInfo>> bundles = container->listBundles();
88 std::list<unique_ptr<RCSBundleInfo>>::iterator bundleIt;
90 cout << "\t>>> bundle list size : " << bundles.size() << endl;
91 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
93 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
96 cout << "\nPress enter to start SO bundle " << endl;
98 container->startBundle("oic.bundle.hueSample");
100 std::map<string, string> resourceParams;
101 cout << "Press enter to add SO bundle resource " << endl;
103 resourceParams["resourceType"] = "oic.r.light";
104 resourceParams["address"] = "http://192.168.0.2/api/newdeveloper/lights/1";
105 container->addResourceConfig("oic.bundle.hueSample", "", resourceParams);
106 container->addResourceConfig("oic.bundle.hueSample", "", resourceParams);
108 std::list<string> resources = container->listBundleResources("oic.bundle.hueSample");
109 std::list<string>::iterator resourceIt;
110 cout << "\t>>> resource list size : " << resources.size() << endl;
111 for (resourceIt = resources.begin(); resourceIt != resources.end(); resourceIt++)
113 cout << "\t>>> resource uri : " << (*resourceIt).c_str() << endl;
116 cout << "\nPress enter to remove SO bundle resource " << endl;
118 container->removeResourceConfig("oic.bundle.hueSample", "/hue/light/1");
120 resources = container->listBundleResources("oic.bundle.hueSample");
121 cout << "\t>>> resource list size : " << resources.size() << endl;
122 for (resourceIt = resources.begin(); resourceIt != resources.end(); resourceIt++)
124 cout << "\t>>> resource uri : " << (*resourceIt).c_str() << endl;
127 cout << "\nPress enter to stop SO Bundle " << endl;
129 container->stopBundle("oic.bundle.hueSample");
131 cout << "Press enter to test remove SO Bundle " << endl;
133 container->removeBundle("oic.bundle.hueSample");
135 bundles = container->listBundles();
136 cout << "\t>>> bundle list size : " << bundles.size() << endl;
137 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
139 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
143 /*java bundle add test*/
144 cout << "\n++++++++++++++++++++++++++++" << endl;
145 cout << "+++ Test for JAVA Bundle +++" << endl;
146 cout << "++++++++++++++++++++++++++++" << endl;
147 cout << "Press enter to add java bundle " << endl;
149 bundleParams["libraryPath"] = ".";
150 std::string activator = "org.iotivity.bundle.hue.HueBundleActivator";
151 container->addBundle("oic.bundle.hueJavaSample2", "/hueJava",
152 "../../../../../../service/resource-container/" \
153 "examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar",
157 bundles = container->listBundles();
158 cout << "\t>>> bundle list size : " << bundles.size() << endl;
159 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
161 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
164 cout << "\nPress enter to start java bundle " << endl;
166 container->startBundle("oic.bundle.hueJavaSample2");
168 cout << "Press enter to stop java Bundle " << endl;
170 container->stopBundle("oic.bundle.hueJavaSample2");
172 cout << "Press enter to test remove java Bundle " << endl;
174 container->removeBundle("oic.bundle.hueJavaSample2");
176 bundles = container->listBundles();
177 cout << "\t>>> bundle list size : " << bundles.size() << endl;
178 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
180 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
184 cout << "\nPress enter to stop container " << endl;
186 container->stopContainer();
188 cout << "Container stopped. Bye" << endl;