Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / things-manager / sampleapp / linux / configuration / DiagnosticsCollection.h
1 //******************************************************************
2 //
3 // Copyright 2014 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 /// This sample shows how one could create a resource (collection) with children.
23 ///
24
25 #include <functional>
26 #include <thread>
27
28 #include "OCPlatform.h"
29 #include "OCApi.h"
30 #include "ThingsManager.h"
31
32 #pragma once
33
34 using namespace OC;
35
36 typedef std::function<
37     OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler;
38
39 static std::string defaultFactoryReset = "false";
40 static std::string defaultReboot = "false";
41 static std::string defaultStartStatCollection = "false";
42
43 class DiagnosticsResource
44 {
45 public:
46
47     // diagnostics members
48     std::string m_diagnosticsUri;
49     std::string m_factoryReset;
50     std::string m_reboot;
51     std::string m_startStatCollection;
52     std::vector< std::string > m_diagnosticsTypes;
53     std::vector< std::string > m_diagnosticsInterfaces;
54     OCResourceHandle m_diagnosticsHandle;
55     OCRepresentation m_diagnosticsRep;
56
57 public:
58     /// Constructor
59     DiagnosticsResource() :
60            m_factoryReset(defaultFactoryReset), m_reboot(defaultReboot),
61             m_startStatCollection(defaultStartStatCollection)
62     {
63         m_diagnosticsUri = "/oic/diag"; // URI of the resource
64         m_diagnosticsTypes.push_back("oic.diag"); // resource type name.
65         m_diagnosticsInterfaces.push_back(DEFAULT_INTERFACE); // resource interface.
66         m_diagnosticsRep.setValue("fr", m_factoryReset);
67         m_diagnosticsRep.setValue("rb", m_reboot);
68         m_diagnosticsRep.setValue("ssc", m_startStatCollection);
69         m_diagnosticsRep.setUri(m_diagnosticsUri);
70         m_diagnosticsRep.setResourceTypes(m_diagnosticsTypes);
71         m_diagnosticsRep.setResourceInterfaces(m_diagnosticsInterfaces);
72         m_diagnosticsHandle = NULL;
73     }
74     ;
75
76     /// This function internally calls registerResource API.
77     void createResources(ResourceEntityHandler callback);
78
79     void setDiagnosticsRepresentation(OCRepresentation& rep);
80
81     OCRepresentation getDiagnosticsRepresentation();
82
83     std::string getUri();
84
85     void diagnosticsMonitor(int second);
86
87     std::function< void() > factoryReset;
88 };
89