Replaced (conditionally) OCCoAPToken with CAToken_t
[platform/upstream/iotivity.git] / resource / csdk / stack / include / internal / ocobserve.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 OC_OBSERVE_H
22 #define OC_OBSERVE_H
23
24 /* In CoAP sequence number is a 24 bit field */
25 #define MAX_SEQUENCE_NUMBER              (0xFFFFFF)
26
27 #define MAX_OBSERVER_FAILED_COMM         (2)
28 #define MAX_OBSERVER_NON_COUNT           (3)
29
30 /* This information is stored for each registerd observer */
31 typedef struct ResourceObserver {
32     // Observation Identifier for request
33     OCObservationId observeId;
34     // URI of observed resource
35     unsigned char *resUri;
36     // Query
37     unsigned char *query;
38 #ifdef CA_INT
39     //token for the observe request
40     CAToken_t token;
41 #else // CA_INT
42     // CoAP token for the observe request
43     OCCoAPToken token;
44 #endif // CA_INT
45     // Resource handle
46     OCResource *resource;
47     // IP address & port of client registered for observe
48     OCDevAddr *addr;
49 #ifdef CA_INT
50     /** Remote Endpoint address **/
51     CAAddress_t addressInfo;
52     /** Connectivity of the endpoint**/
53     CAConnectivityType_t connectivityType;
54 #endif
55     // Quality of service of the request
56     OCQualityOfService qos;
57     // number of times the server failed to reach the observer
58     uint8_t failedCommCount;
59     // number of times the server sent NON notifications
60     uint8_t lowQosCount;
61     // force the qos value to CON
62     uint8_t forceHighQos;
63     // next node in this list
64     struct ResourceObserver *next;
65 } ResourceObserver;
66
67 #ifdef WITH_PRESENCE
68 OCStackResult SendAllObserverNotification (OCMethod method, OCResource *resPtr, uint32_t maxAge,
69         OCResourceType *resourceType, OCQualityOfService qos);
70 #else
71 OCStackResult SendAllObserverNotification (OCMethod method, OCResource *resPtr, uint32_t maxAge,
72         OCQualityOfService qos);
73 #endif
74 OCStackResult SendListObserverNotification (OCResource * resource,
75         OCObservationId  *obsIdList, uint8_t numberOfIds,
76         unsigned char *notificationJSONPayload, uint32_t maxAge,
77         OCQualityOfService qos);
78
79 void DeleteObserverList();
80
81 OCStackResult GenerateObserverId (OCObservationId *observationId);
82
83
84
85 #ifdef CA_INT
86 OCStackResult AddObserver (const char         *resUri,
87                            const char         *query,
88                            OCObservationId    obsId,
89                            CAToken_t          *token,
90                            OCDevAddr          *addr,
91                            OCResource         *resHandle,
92                            OCQualityOfService qos,
93                            CAAddress_t          *addressInfo,
94                            CAConnectivityType_t connectivityType);
95
96 OCStackResult DeleteObserverUsingToken (CAToken_t * token);
97 ResourceObserver* GetObserverUsingToken (const CAToken_t * token);
98 #else
99 OCStackResult AddObserver (const char         *resUri,
100                            const char         *query,
101                            OCObservationId    obsId,
102                            OCCoAPToken        *token,
103                            OCDevAddr          *addr,
104                            OCResource         *resHandle,
105                            OCQualityOfService qos);
106
107 OCStackResult DeleteObserverUsingToken (OCCoAPToken * token);
108 ResourceObserver* GetObserverUsingToken (const OCCoAPToken * token);
109 #endif
110
111 ResourceObserver* GetObserverUsingId (const OCObservationId observeId);
112
113 #ifdef CA_INT
114
115 OCStackResult
116 CreateObserveHeaderOption (CAHeaderOption_t **caHdrOpt,
117                            OCHeaderOption *ocHdrOpt,
118                            uint8_t numOptions,
119                            uint8_t observeFlag);
120 OCStackResult
121 GetObserveHeaderOption (uint32_t * observationOption,
122                         CAHeaderOption_t *options,
123                         uint8_t * numOptions);
124 #endif // CA_INT
125
126 #endif //OC_OBSERVE_H