Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / resource-encapsulation / src / resourceBroker / include / BrokerTypes.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 #ifndef RB_BROKERTYPES_H_
22 #define RB_BROKERTYPES_H_
23
24 #include <iostream>
25 #include <functional>
26 #include <list>
27
28 #include "logger.h"
29 #include "PrimitiveResource.h"
30
31 namespace OIC
32 {
33     namespace Service
34     {
35         #define BROKER_TAG "BROKER"
36         #define BROKER_DEVICE_PRESENCE_TIMEROUT (15000l)
37         #define BROKER_SAFE_SECOND (5l)
38         #define BROKER_SAFE_MILLISECOND (BROKER_SAFE_SECOND * (1000))
39         #define BROKER_TRANSPORT OCConnectivityType::CT_ADAPTER_IP
40
41         /*
42          * @BROKER_STATE
43          * brief : resourcePresence state
44          * ALIVE       - It means that 'getCB' function receives 'OK' message
45          * REQUESTED   - It means that broker receives the request for presence checking
46          * LOST_SIGNAL - In case that 'getCB' function receives the message except 'OK'
47          * DESTROYED   - In case that the presence checking is dismissed for the resource ,
48          *               or there is no matched value in the Broker Callback list
49          * NONE        - To be determined.
50          */
51         enum class BROKER_STATE
52         {
53             ALIVE = 0,
54             REQUESTED,
55             LOST_SIGNAL,
56             DESTROYED,
57             NONE
58         };
59
60         /*
61          * @DEVICE_STATE
62          * brief : devicePresence state
63          * ALIVE       - It means that 'subscribeCB' function receives 'OK' message
64          * REQUESTED   - It means that broker receives the request for presence checking
65          * LOST_SIGNAL - In case that 'subscribeCB' function receives the message except 'OK'
66          */
67         enum class DEVICE_STATE
68         {
69             ALIVE = 0,
70             REQUESTED,
71             LOST_SIGNAL
72         };
73
74         enum class BROKER_MODE
75         {
76             DEVICE_PRESENCE_MODE = 0,
77             NON_PRESENCE_MODE
78         };
79
80         typedef unsigned int BrokerID;
81
82         typedef std::function<void(BROKER_STATE)> BrokerCB;
83         struct BrokerRequesterInfo
84         {
85             BrokerRequesterInfo(BrokerID _id, BrokerCB _cb) : brokerId(_id), brokerCB(_cb){}
86             BrokerID brokerId;
87             BrokerCB brokerCB;
88         };
89         typedef std::shared_ptr<BrokerRequesterInfo> BrokerRequesterInfoPtr;
90
91         class ResourcePresence;
92         class DevicePresence;
93
94         typedef std::function<void(std::shared_ptr<OC::OCResource>)> FindCB;
95
96         typedef std::shared_ptr<PrimitiveResource> PrimitiveResourcePtr;
97
98         typedef std::shared_ptr<ResourcePresence> ResourcePresencePtr;
99         typedef std::shared_ptr<DevicePresence> DevicePresencePtr;
100         typedef std::list< ResourcePresencePtr > PresenceList;
101
102         struct BrokerCBResourcePair
103         {
104             BrokerCBResourcePair(ResourcePresencePtr pResource, BrokerCB cb)
105             : pResource(pResource), brokerCB(cb){}
106             ResourcePresencePtr pResource;
107             BrokerCB brokerCB;
108         };
109         typedef std::map<BrokerID, BrokerCBResourcePair> BrokerIDMap;
110
111         typedef std::function<void(OCStackResult, const unsigned int,
112                 const std::string&)> SubscribeCB;
113
114         typedef std::function<void(const HeaderOptions&, const ResponseStatement&, int)> RequestGetCB;
115         typedef std::function<void(long long)> TimerCB;
116     } // namespace Service
117 } // namespace OIC
118
119 #endif // RB_BROKERTYPES_H_