update container and sample bundles for so bundle dynamic configuraion
[platform/upstream/iotivity.git] / service / resource-manipulation / src / resourceContainer / src / ContainerSample.cpp
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #include "ResourceContainer.h"
22 #include "BundleInfo.h"
23 #include "oc_logger.hpp"
24 #include <iostream>
25
26 using namespace std;
27 using namespace OIC::Service;
28 using OC::oc_log_stream;
29
30 /* Annother way to create a context: */
31 auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
32 {
33     static OC::oc_log_stream ols(oc_make_ostream_logger);
34     static boost::iostreams::stream<OC::oc_log_stream> os(ols);
35
36     return os;
37 };
38
39 int main()
40 {
41     info_logger()->set_module("ContainerTest");
42     info_logger()->set_level(OC_LOG_INFO);
43
44     info_logger() << "Starting container test." << std::flush;
45
46     ResourceContainer *container = ResourceContainer::getInstance();
47     container->startContainer("examples/ResourceContainerConfig.xml");
48
49     /*so bundle add test*/
50     cout << "++++++++++++++++++++++++++" << endl;
51     cout << "+++ Test for SO Bundle +++" << endl;
52     cout << "++++++++++++++++++++++++++" << endl;
53     cout << "Press enter to add SO bundle " << endl;
54     getchar();
55     std::map<string, string> bundleParams;
56     container->addBundle("oic.bundle.hueSample", "", "libHueBundle.so", bundleParams);
57
58     std::list<BundleInfo *> bundles = container->listBundles();
59     std::list<BundleInfo *>::iterator bundleIt;
60
61     cout << "\t>>> bundle list size : " << bundles.size() << endl;
62     for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
63     {
64         cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
65     }
66
67     cout << "\nPress enter to start SO bundle " << endl;
68     getchar();
69     container->startBundle("oic.bundle.hueSample");
70
71     std::map<string, string> resourceParams;
72     cout << "Press enter to add SO bundle resource " << endl;
73     getchar();
74     resourceParams["resourceType"] = "oic.light.control";
75     resourceParams["address"] = "http://192.168.0.2/api/newdeveloper/lights/1";
76     container->addResourceConfig("oic.bundle.hueSample", "", resourceParams);
77     container->addResourceConfig("oic.bundle.hueSample", "", resourceParams);
78
79     std::list<string> resources = container->listBundleResources("oic.bundle.hueSample");
80     std::list<string>::iterator resourceIt;
81     cout << "\t>>> resource list size : " << resources.size() << endl;
82     for (resourceIt = resources.begin(); resourceIt != resources.end(); resourceIt++)
83     {
84         cout << "\t>>> resource uri : " << (*resourceIt).c_str() << endl;
85     }
86
87     cout << "\nPress enter to remove SO bundle resource " << endl;
88     getchar();
89     container->removeResourceConfig("oic.bundle.hueSample", "/hue/light/1");
90
91     resources = container->listBundleResources("oic.bundle.hueSample");
92     cout << "\t>>> resource list size : " << resources.size() << endl;
93     for (resourceIt = resources.begin(); resourceIt != resources.end(); resourceIt++)
94     {
95         cout << "\t>>> resource uri : " << (*resourceIt).c_str() << endl;
96     }
97
98     cout << "\nPress enter to stop SO Bundle " << endl;
99     getchar();
100     container->stopBundle("oic.bundle.hueSample");
101
102     cout << "Press enter to test remove SO Bundle " << endl;
103     getchar();
104     container->removeBundle("oic.bundle.hueSample");
105
106     bundles = container->listBundles();
107     cout << "\t>>> bundle list size : " << bundles.size() << endl;
108     for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
109     {
110         cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
111     }
112
113     /*java bundle add test*/
114     cout << "\n++++++++++++++++++++++++++++" << endl;
115     cout << "+++ Test for JAVA Bundle +++" << endl;
116     cout << "++++++++++++++++++++++++++++" << endl;
117     cout << "Press enter to add java bundle " << endl;
118     getchar();
119     bundleParams["libraryPath"] = ".";
120     bundleParams["activator"] = "org.iotivity.bundle.hue.HueBundleActivator";
121     container->addBundle("oic.bundle.hueJavaSample", "/hueJava",
122                          "../../../../../../../../service/resource-manipulation/src/resourceContainer/examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar",
123                          bundleParams);
124
125     bundles = container->listBundles();
126     cout << "\t>>> bundle list size : " << bundles.size() << endl;
127     for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
128     {
129         cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
130     }
131
132     cout << "\nPress enter to start java bundle " << endl;
133     getchar();
134     container->startBundle("oic.bundle.hueJavaSample");
135
136     cout << "Press enter to stop java Bundle " << endl;
137     getchar();
138     container->stopBundle("oic.bundle.hueJavaSample");
139
140     cout << "Press enter to test remove java Bundle " << endl;
141     getchar();
142     container->removeBundle("oic.bundle.hueJavaSample");
143
144     bundles = container->listBundles();
145     cout << "\t>>> bundle list size : " << bundles.size() << endl;
146     for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
147     {
148         cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
149     }
150
151     cout << "\nPress enter to stop container " << endl;
152     getchar();
153     container->stopContainer();
154
155     cout << "Container stopped. Bye" << endl;
156 }