Implementation of APIs for managing resource list and callback
[platform/upstream/iotivity.git] / service / simulator / src / simulator_manager.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 "simulator_manager.h"
22 #include "resource_manager.h"
23 #include "simulator_client.h"
24
25 using namespace OC;
26
27 SimulatorManager *SimulatorManager::getInstance()
28 {
29     static SimulatorManager s_instance;
30     return &s_instance;
31 }
32
33 SimulatorManager::SimulatorManager()
34 {
35     OC::PlatformConfig conf
36     {
37         OC::ServiceType::InProc,
38         OC::ModeType::Both,
39         "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
40         0,         // Uses randomly available port
41         OC::QualityOfService::LowQos
42     };
43
44     OC::OCPlatform::Configure(conf);
45 }
46
47 SimulatorResourceServerPtr SimulatorManager::createResource(const std::string &configPath,
48         SimulatorResourceServer::ResourceModelChangedCB callback)
49 {
50     return ResourceManager::getInstance()->createResource(configPath, callback);
51 }
52
53 std::vector<SimulatorResourceServerPtr> SimulatorManager::createResource(
54     const std::string &configPath,
55     const int count, SimulatorResourceServer::ResourceModelChangedCB callback)
56 {
57     return ResourceManager::getInstance()->createResource(configPath, count, callback);
58 }
59
60 std::vector<SimulatorResourceServerPtr> SimulatorManager::getResources(
61     const std::string &resourceType)
62 {
63     return ResourceManager::getInstance()->getResources(resourceType);
64 }
65
66 SimulatorResult SimulatorManager::deleteResource(SimulatorResourceServerPtr &resource)
67 {
68     return ResourceManager::getInstance()->deleteResource(resource);
69 }
70
71 SimulatorResult SimulatorManager::deleteResources(const std::string &resourceType)
72 {
73     return ResourceManager::getInstance()->deleteResources(resourceType);
74 }
75
76 SimulatorResult SimulatorManager::findResource(const std::string &resourceType,
77         ResourceFindCallback callback)
78 {
79     return SimulatorClient::getInstance()->findResource(resourceType, callback);
80 }
81
82 std::vector<SimulatorRemoteResourcePtr> SimulatorManager::getFoundResources(
83     const std::string resourceType)
84 {
85     return SimulatorClient::getInstance()->getFoundResources(resourceType);
86 }
87
88 void SimulatorManager::setLogger(std::shared_ptr<ILogger> logger)
89 {
90     simLogger().setCustomTarget(logger);
91 }
92
93 bool SimulatorManager::setDefaultConsoleLogger()
94 {
95     return simLogger().setDefaultConsoleTarget();
96 }
97
98 bool SimulatorManager::setDefaultFileLogger(std::string &path)
99 {
100     return simLogger().setDefaultFileTarget(path);
101 }