Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / things-manager / unittests / MaintenanceCollection.h
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 ///
22 /// create a resource (collection) with children.
23 ///
24
25 #include <functional>
26 #include <thread>
27
28 #include "OCPlatform.h"
29 #include "OCApi.h"
30
31 #pragma once
32
33 using namespace OC;
34
35 typedef std::function <
36 OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
37
38 static std::string defaultMntURI = "/oic/mnt";
39 static std::string defaultMntResourceType = "oic.wk.mnt";
40
41 static std::string defaultFactoryReset = "false";
42 static std::string defaultReboot = "false";
43 static std::string defaultStartStatCollection = "false";
44
45 class MaintenanceResource
46 {
47     public:
48
49         // Maintenance members
50         std::string m_maintenanceUri;
51         std::string m_factoryReset;
52         std::string m_reboot;
53         std::string m_startStatCollection;
54         std::vector< std::string > m_maintenanceTypes;
55         std::vector< std::string > m_maintenanceInterfaces;
56         OCResourceHandle m_maintenanceHandle;
57         OCRepresentation m_maintenanceRep;
58
59     public:
60         /// Constructor
61         MaintenanceResource() :
62             m_factoryReset(defaultFactoryReset), m_reboot(defaultReboot),
63             m_startStatCollection(defaultStartStatCollection)
64         {
65             m_maintenanceUri = defaultMntURI; // URI of the resource
66             m_maintenanceTypes.push_back(defaultMntResourceType); // resource type name.
67             m_maintenanceInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
68             m_maintenanceRep.setValue("fr", m_factoryReset);
69             m_maintenanceRep.setValue("rb", m_reboot);
70             m_maintenanceRep.setValue("ssc", m_startStatCollection);
71             m_maintenanceRep.setUri(m_maintenanceUri);
72             m_maintenanceRep.setResourceTypes(m_maintenanceTypes);
73             m_maintenanceRep.setResourceInterfaces(m_maintenanceInterfaces);
74             m_maintenanceHandle = NULL;
75         }
76         ;
77
78         /// This function internally calls registerResource API.
79         void createResources(ResourceEntityHandler callback);
80
81         void setMaintenanceRepresentation(OCRepresentation &rep);
82
83         OCRepresentation getMaintenanceRepresentation();
84
85         std::string getUri();
86
87         void maintenanceMonitor(int second);
88
89         std::function< void() > factoryReset;
90 };
91