Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / resource-container / unittests / TestBundle / src / TestBundleActivator.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 "TestBundleActivator.h"
22
23 TestBundleActivator *bundle;
24
25 TestBundleActivator::TestBundleActivator()
26 {
27     m_pResourceContainer = nullptr;
28     m_pTestResource = nullptr;
29 }
30
31 TestBundleActivator::~TestBundleActivator()
32 {
33     m_pResourceContainer = nullptr;
34     m_pTestResource = nullptr;
35 }
36
37 void TestBundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
38         std::string bundleId)
39 {
40     std::cout << "TestBundleActivator::activateBundle .. " << std::endl;
41     m_pResourceContainer = resourceContainer;
42     m_bundleId = bundleId;
43 }
44
45 void TestBundleActivator::deactivateBundle()
46 {
47     std::cout << "TestBundleActivator::deactivateBundle .. " << std::endl;
48     m_pResourceContainer = nullptr;
49 }
50
51 void TestBundleActivator::createResource(resourceInfo resourceInfo)
52 {
53     std::cout << "TestBundleActivator::createResource .. " << std::endl;
54
55     m_pTestResource = std::make_shared< TestBundleResource >();
56
57     m_pTestResource->m_bundleId = m_bundleId;
58     m_pTestResource->m_uri = resourceInfo.uri;
59     m_pTestResource->m_resourceType = resourceInfo.resourceType;
60
61     m_pResourceContainer->registerResource(m_pTestResource);
62 }
63
64 void TestBundleActivator::destroyResource(BundleResource::Ptr pBundleResource)
65 {
66     std::cout << "TestBundleActivator::destroyResource .. " << std::endl;
67
68     m_pResourceContainer->unregisterResource(pBundleResource);
69 }
70
71 extern "C" void test_externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
72         std::string bundleId)
73 {
74     bundle = new TestBundleActivator();
75     bundle->activateBundle(resourceContainer, bundleId);
76 }
77
78 extern "C" void test_externalDeactivateBundle()
79 {
80     bundle->deactivateBundle();
81     delete bundle;
82 }
83
84 extern "C" void test_externalCreateResource(resourceInfo resourceInfo)
85 {
86     bundle->createResource(resourceInfo);
87 }
88
89 extern "C" void test_externalDestroyResource(BundleResource::Ptr pBundleResource)
90 {
91     bundle->destroyResource(pBundleResource);
92 }