Merge branch 'master' into resource-manipulation
[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 OIC::Service;
27 using OC::oc_log_stream;
28
29 /* Annother way to create a context: */
30 auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
31 {
32     static OC::oc_log_stream ols(oc_make_ostream_logger);
33     static boost::iostreams::stream<OC::oc_log_stream> os(ols);
34
35     return os;
36 };
37
38 int main()
39 {
40     info_logger()->set_module("ContainerTest");
41     info_logger()->set_level(OC_LOG_INFO);
42
43     info_logger() << "Starting container test." << std::flush;
44
45     ResourceContainer *container = ResourceContainer::getInstance();
46     container->startContainer("examples/ResourceContainerConfig.xml");
47
48     std::list<BundleInfo*> bundles = container->listBundles();
49     std::list<BundleInfo*>::iterator bundleIt;
50
51     for(bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++){
52         BundleInfo* bi = *bundleIt;
53         info_logger() << "Available bundle: " << bi->getID() << endl;
54     }
55
56     cout << "Press enter to stop all bundles " << endl;
57     getchar();
58
59     for(bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++){
60         BundleInfo* bi = *bundleIt;
61         info_logger() << "Stopping bundle: " << bi->getID() << endl;
62         container->stopBundle(bi->getID());
63     }
64
65     cout << "Press enter to restart all bundles " << endl;
66     getchar();
67
68     for(bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++){
69         BundleInfo* bi = *bundleIt;
70         info_logger() << "Starting bundle: " << bi->getID() << endl;
71         container->startBundle(bi->getID());
72     }
73
74     cout << "Press enter to stop container " << endl;
75     getchar();
76     container->stopContainer();
77     cout << "Container stopped. Bye" << endl;
78 }