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"
31 using namespace OIC::Service;
35 void getCurrentPath(std::string *pPath)
37 char buffer[MAX_PATH];
39 #if defined(__linux__)
41 int length = readlink("/proc/self/exe", buffer, MAX_PATH - 1);
45 buffer[length] = '\0';
46 strPath = strrchr(buffer, '/');
52 pPath->append(buffer);
57 cout << "Starting container test." << endl;
59 std::string strConfigPath;
60 getCurrentPath(&strConfigPath);
61 strConfigPath.append("/examples/ResourceContainerConfig.xml");
63 RCSResourceContainer *container = RCSResourceContainer::getInstance();
64 container->startContainer(strConfigPath);
66 /*so bundle add test*/
67 cout << "++++++++++++++++++++++++++" << endl;
68 cout << "+++ Test for SO Bundle +++" << endl;
69 cout << "++++++++++++++++++++++++++" << endl;
70 cout << "Press enter to add SO bundle " << endl;
72 std::map<string, string> bundleParams;
73 container->addBundle("oic.bundle.hueSample", "", "libHueBundle.so", "huesample", bundleParams);
75 std::list<unique_ptr<RCSBundleInfo>> bundles = container->listBundles();
76 std::list<unique_ptr<RCSBundleInfo>>::iterator bundleIt;
78 cout << "\t>>> bundle list size : " << bundles.size() << endl;
79 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
81 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
84 cout << "\nPress enter to start SO bundle " << endl;
86 container->startBundle("oic.bundle.hueSample");
88 std::map<string, string> resourceParams;
89 cout << "Press enter to add SO bundle resource " << endl;
91 resourceParams["resourceType"] = "oic.r.light";
92 resourceParams["address"] = "http://192.168.0.2/api/newdeveloper/lights/1";
93 container->addResourceConfig("oic.bundle.hueSample", "", resourceParams);
94 container->addResourceConfig("oic.bundle.hueSample", "", resourceParams);
96 std::list<string> resources = container->listBundleResources("oic.bundle.hueSample");
97 std::list<string>::iterator resourceIt;
98 cout << "\t>>> resource list size : " << resources.size() << endl;
99 for (resourceIt = resources.begin(); resourceIt != resources.end(); resourceIt++)
101 cout << "\t>>> resource uri : " << (*resourceIt).c_str() << endl;
104 cout << "\nPress enter to remove SO bundle resource " << endl;
106 container->removeResourceConfig("oic.bundle.hueSample", "/hue/light/1");
108 resources = container->listBundleResources("oic.bundle.hueSample");
109 cout << "\t>>> resource list size : " << resources.size() << endl;
110 for (resourceIt = resources.begin(); resourceIt != resources.end(); resourceIt++)
112 cout << "\t>>> resource uri : " << (*resourceIt).c_str() << endl;
115 cout << "\nPress enter to stop SO Bundle " << endl;
117 container->stopBundle("oic.bundle.hueSample");
119 cout << "Press enter to test remove SO Bundle " << endl;
121 container->removeBundle("oic.bundle.hueSample");
123 bundles = container->listBundles();
124 cout << "\t>>> bundle list size : " << bundles.size() << endl;
125 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
127 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
131 /*java bundle add test*/
132 cout << "\n++++++++++++++++++++++++++++" << endl;
133 cout << "+++ Test for JAVA Bundle +++" << endl;
134 cout << "++++++++++++++++++++++++++++" << endl;
135 cout << "Press enter to add java bundle " << endl;
137 bundleParams["libraryPath"] = ".";
138 std::string activator = "org.iotivity.bundle.hue.HueBundleActivator";
139 container->addBundle("oic.bundle.hueJavaSample2", "/hueJava",
140 "../../../../../../service/resource-container/" \
141 "examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar",
145 bundles = container->listBundles();
146 cout << "\t>>> bundle list size : " << bundles.size() << endl;
147 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
149 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
152 cout << "\nPress enter to start java bundle " << endl;
154 container->startBundle("oic.bundle.hueJavaSample2");
156 cout << "Press enter to stop java Bundle " << endl;
158 container->stopBundle("oic.bundle.hueJavaSample2");
160 cout << "Press enter to test remove java Bundle " << endl;
162 container->removeBundle("oic.bundle.hueJavaSample2");
164 bundles = container->listBundles();
165 cout << "\t>>> bundle list size : " << bundles.size() << endl;
166 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
168 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
172 cout << "\nPress enter to stop container " << endl;
174 container->stopContainer();
176 cout << "Container stopped. Bye" << endl;