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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 /// create a resource (collection) with children.
28 #include "OCPlatform.h"
35 typedef std::function <
36 OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
38 static std::string defaultMntURI = "/oic/mnt";
39 static std::string defaultMntResourceType = "oic.wk.mnt";
41 static std::string defaultFactoryReset = "false";
42 static std::string defaultReboot = "false";
43 static std::string defaultStartStatCollection = "false";
45 class MaintenanceResource
49 // Maintenance members
50 std::string m_maintenanceUri;
51 std::string m_factoryReset;
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;
61 MaintenanceResource() :
62 m_factoryReset(defaultFactoryReset), m_reboot(defaultReboot),
63 m_startStatCollection(defaultStartStatCollection)
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;
78 /// This function internally calls registerResource API.
79 void createResources(ResourceEntityHandler callback);
81 void setMaintenanceRepresentation(OCRepresentation &rep);
83 OCRepresentation getMaintenanceRepresentation();
87 void maintenanceMonitor(int second);
89 std::function< void() > factoryReset;