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 #include "ResourceContainer.h"
22 #include "BundleInfo.h"
23 #include "oc_logger.hpp"
26 using namespace OIC::Service;
27 using OC::oc_log_stream;
29 /* Annother way to create a context: */
30 auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
32 static OC::oc_log_stream ols(oc_make_ostream_logger);
33 static boost::iostreams::stream<OC::oc_log_stream> os(ols);
40 info_logger()->set_module("ContainerTest");
41 info_logger()->set_level(OC_LOG_INFO);
43 info_logger() << "Starting container test." << std::flush;
45 ResourceContainer *container = ResourceContainer::getInstance();
46 container->startContainer("examples/ResourceContainerConfig.xml");
48 std::list<BundleInfo*> bundles = container->listBundles();
49 std::list<BundleInfo*>::iterator bundleIt;
51 for(bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++){
52 BundleInfo* bi = *bundleIt;
53 info_logger() << "Available bundle: " << bi->getID() << endl;
56 cout << "Press enter to stop all bundles " << endl;
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());
65 cout << "Press enter to restart all bundles " << endl;
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());
74 cout << "Press enter to stop container " << endl;
76 container->stopContainer();
77 cout << "Container stopped. Bye" << endl;