Merge "[CA] [All] URI support , Optimization , License verification" into connectivit...
[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     // CoAP token for the observe request
39     OCCoAPToken token;
40     // Resource handle
41     OCResource *resource;
42     // IP address & port of client registered for observe
43     OCDevAddr *addr;
44 #ifdef CA_INT
45     /** Remote Endpoint address **/
46     CAAddress_t addressInfo;
47     /** Connectivity of the endpoint**/
48     CAConnectivityType_t connectivityType;
49     char CAToken[32];   // TODO-CA:  What is max CAToken_t length?  Get rid of magic number
50 #endif
51     // Quality of service of the request
52     OCQualityOfService qos;
53     // number of times the server failed to reach the observer
54     uint8_t failedCommCount;
55     // number of times the server sent NON notifications
56     uint8_t lowQosCount;
57     // force the qos value to CON
58     uint8_t forceHighQos;
59     // next node in this list
60     struct ResourceObserver *next;
61 } ResourceObserver;
62
63 #ifdef WITH_PRESENCE
64 OCStackResult SendAllObserverNotification (OCMethod method, OCResource *resPtr, uint32_t maxAge,
65         OCResourceType *resourceType, OCQualityOfService qos);
66 #else
67 OCStackResult SendAllObserverNotification (OCMethod method, OCResource *resPtr, uint32_t maxAge,
68         OCQualityOfService qos);
69 #endif
70 OCStackResult SendListObserverNotification (OCResource * resource,
71         OCObservationId  *obsIdList, uint8_t numberOfIds,
72         unsigned char *notificationJSONPayload, uint32_t maxAge,
73         OCQualityOfService qos);
74
75 void DeleteObserverList();
76
77 OCStackResult GenerateObserverId (OCObservationId *observationId);
78
79 OCStackResult AddObserver (const char         *resUri,
80                            const char         *query,
81                            OCObservationId    obsId,
82                            OCCoAPToken        *token,
83                            OCDevAddr          *addr,
84                            OCResource         *resHandle,
85                            OCQualityOfService qos);
86
87 OCStackResult DeleteObserverUsingToken (OCCoAPToken * token);
88
89 ResourceObserver* GetObserverUsingToken (const OCCoAPToken * token);
90
91 ResourceObserver* GetObserverUsingId (const OCObservationId observeId);
92
93 #ifdef CA_INT
94 OCStackResult AddCAObserver (const char         *resUri,
95                            const char           *query,
96                            OCObservationId      obsId,
97                            OCCoAPToken          *token,
98                            OCDevAddr            *addr,
99                            OCResource           *resHandle,
100                            OCQualityOfService   qos,
101                            CAAddress_t          *addressInfo,
102                            CAConnectivityType_t connectivityType,
103                            char                 *CAtoken);
104
105 OCStackResult
106 CreateObserveHeaderOption (CAHeaderOption_t **caHdrOpt,
107                            OCHeaderOption *ocHdrOpt,
108                            uint8_t numOptions,
109                            uint8_t observeFlag);
110 OCStackResult
111 GetObserveHeaderOption (uint32_t * observationOption,
112                         CAHeaderOption_t *options,
113                         uint8_t * numOptions);
114 #endif // CA_INT
115
116 #endif //OC_OBSERVE_H