Update container and build script for rearrangement of headers
[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     std::list<BundleInfo *> bundles = container->listBundles();
50     std::list<BundleInfo *>::iterator bundleIt;
51
52     for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
53     {
54         BundleInfo *bi = *bundleIt;
55         info_logger() << "Available bundle: " << bi->getID() << endl;
56     }
57
58     cout << "Press enter to stop all bundles " << endl;
59     getchar();
60
61     for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
62     {
63         BundleInfo *bi = *bundleIt;
64         info_logger() << "Stopping bundle: " << bi->getID() << endl;
65         container->stopBundle(bi->getID());
66     }
67
68     cout << "Press enter to restart all bundles " << endl;
69     getchar();
70
71     for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
72     {
73         BundleInfo *bi = *bundleIt;
74         info_logger() << "Starting bundle: " << bi->getID() << endl;
75         container->startBundle(bi->getID());
76     }
77
78     cout << "Press enter to stop container " << endl;
79     getchar();
80     container->stopContainer();
81     cout << "Container stopped. Bye" << endl;
82 }