Merge "Partial Implementation of US1574:"
[platform/upstream/iotivity.git] / csdk / controller / core / include / core / InternalApi.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH 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 #ifndef INTERNALAPI_H_
22 #define INTERNALAPI_H_
23
24 // ============================================================================
25 // Includes
26 // ============================================================================
27 #include <memory>
28 #include <functional>
29 #include <string>
30 #include <list>
31 #include "Core.h"
32 #include "Description.hpp"
33 #include "Characteristic.hpp"
34 #include "Protocol.hpp"
35 #include "Device.hpp"
36
37 // ============================================================================
38 // Namespace
39 // ============================================================================
40 namespace Intel {
41 namespace CCFL {
42 namespace API {
43
44
45 // ============================================================================
46 //                              Device Class(es)
47 // ============================================================================
48
49 #if 0
50 // ============================================================================
51 // Class
52 // ============================================================================
53 class DeviceIdsGetResult {
54         // ============================================================
55         // Destructor
56         // ============================================================
57         public:
58                 virtual ~DeviceIdsGetResult() {}
59
60         // ============================================================
61         // Public Method(s)
62         // ============================================================
63         public:
64                 virtual QueryResultType getResult() const = 0;
65                 virtual const std::set<UUID_t>& getDeviceIds() const = 0;
66 };
67
68 typedef std::function<void (const DeviceIdsGetResult&)> DeviceIdsGetFunction;
69
70 // ============================================================================
71 // Class
72 // ============================================================================
73 class DeviceGetInfoResult {
74         // ============================================================
75         // Destructor
76         // ============================================================
77         public:
78                 virtual ~DeviceGetInfoResult() {}
79
80         // ============================================================
81         // Public Method(s)
82         // ============================================================
83         public:
84                 virtual QueryResultType getResult() const = 0;
85                 virtual const std::string& getName() const = 0;
86                 virtual const Description::SharedPtr& getDescription() const = 0;
87                 virtual bool isLocal() = 0;
88 };
89
90 typedef std::function<void (const DeviceGetInfoResult&)> DeviceGetInfoFunction;
91 #endif
92
93 // ============================================================================
94 // Class
95 // ============================================================================
96 class GetDevicesResult {
97         // ============================================================
98         // Destructor
99         // ============================================================
100         public:
101                 virtual ~GetDevicesResult() {}
102
103         // ============================================================
104         // Public Method(s)
105         // ============================================================
106         public:
107                 virtual QueryResultType getResult() const = 0;
108                 virtual const std::list<Device::SharedPtr>& getDeviceList() const = 0;
109 };
110
111 typedef std::function<void (const GetDevicesResult&)> GetDevicesFunction;
112
113
114 // ============================================================================
115 // Class
116 // ============================================================================
117 typedef uint32_t DeviceObserverHandle;
118 const DeviceObserverHandle INVALID_DEVICE_OBSERVER_HANDLE = (DeviceObserverHandle)0;
119
120 class DeviceEvent {
121 public:
122         enum DeviceChange {
123                 DEVICE_CURRENT_COLLECTION,
124                 DEVICE_ADDED,
125                 DEVICE_REMOVED
126         };
127
128         struct DeviceEventInfo {
129                 UUID_t       deviceId;
130                 DeviceChange deviceChange;
131         };
132         // ============================================================
133         // Destructor
134         // ============================================================
135         public:
136                 virtual ~DeviceEvent() {}
137
138         // ============================================================
139         // Public Method(s)
140         // ============================================================
141         public:
142                 virtual QueryResultType getResult() const = 0;
143                 virtual DeviceObserverHandle getObserverHandle() const = 0;
144                 virtual const std::list<DeviceEventInfo>& getDeviceIdList() const = 0;
145 };
146
147 typedef std::function<void (const DeviceEvent&)> DeviceEventFunction;
148
149
150 // ============================================================================
151 // Class
152 // ============================================================================
153 class Model : public std::enable_shared_from_this<Model> {
154         // ============================================================
155         // Type Definition(s)
156         // ============================================================
157         public:
158                 typedef std::shared_ptr<Model> SharedPtr;
159                 typedef std::weak_ptr<Model> WeakPtr;
160
161         // ============================================================
162         // Factory
163         // ============================================================
164         public:
165                 static SharedPtr createModel();
166
167         // ============================================================
168         // Destructor
169         // ============================================================
170         public:
171                 virtual ~Model() {}
172
173         // ============================================================
174         // Public Method(s)
175         // ============================================================
176         public:
177                 virtual void getDevices(GetDevicesFunction& asyncReturnFunc) = 0;
178
179                 // Add/remove device observer
180                 virtual void removeDeviceObserver(DeviceObserverHandle observerHandle) = 0;
181                 virtual void setDeviceObserver(DeviceEventFunction& asyncEventFunction) = 0;
182
183                 // Register/unregister a protocol
184                 virtual const Protocols::Protocol::Handle registerProtocol(const Protocols::Protocol::SharedPtr& protocol) = 0;
185                 virtual bool unregisterProtocol(const Protocols::Protocol::Handle protocolHandle) = 0;
186     virtual Device::SharedPtr getDevice(const UUID_t& deviceId) = 0;
187     virtual void signalDeviceChange(const UUID_t& deviceId, DeviceEvent::DeviceChange deviceEvent) = 0;
188
189 };
190
191
192 }
193 }
194 }
195
196 #endif /* INTERNALAPI_H_ */