1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 /* In CoAP sequence number is a 24 bit field */
25 #define MAX_SEQUENCE_NUMBER (0xFFFFFF)
27 #define MAX_OBSERVER_FAILED_COMM (2)
28 #define MAX_OBSERVER_NON_COUNT (3)
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;
38 // CoAP token for the observe request
42 // IP address & port of client registered for observe
45 /** Remote Endpoint address **/
46 CAAddress_t addressInfo;
47 /** Connectivity of the endpoint**/
48 CAConnectivityType_t connectivityType;
49 char CAToken[CA_MAX_TOKEN_LEN+1];
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
57 // force the qos value to CON
59 // next node in this list
60 struct ResourceObserver *next;
64 OCStackResult SendAllObserverNotification (OCMethod method, OCResource *resPtr, uint32_t maxAge,
65 OCResourceType *resourceType, OCQualityOfService qos);
67 OCStackResult SendAllObserverNotification (OCMethod method, OCResource *resPtr, uint32_t maxAge,
68 OCQualityOfService qos);
70 OCStackResult SendListObserverNotification (OCResource * resource,
71 OCObservationId *obsIdList, uint8_t numberOfIds,
72 unsigned char *notificationJSONPayload, uint32_t maxAge,
73 OCQualityOfService qos);
75 void DeleteObserverList();
77 OCStackResult GenerateObserverId (OCObservationId *observationId);
79 OCStackResult AddObserver (const char *resUri,
81 OCObservationId obsId,
84 OCResource *resHandle,
85 OCQualityOfService qos);
88 OCStackResult DeleteObserverUsingToken (char * token);
90 OCStackResult DeleteObserverUsingToken (OCCoAPToken * token);
94 ResourceObserver* GetObserverUsingToken (const char * token);
96 ResourceObserver* GetObserverUsingToken (const OCCoAPToken * token);
99 ResourceObserver* GetObserverUsingId (const OCObservationId observeId);
102 OCStackResult AddCAObserver (const char *resUri,
104 OCObservationId obsId,
107 OCResource *resHandle,
108 OCQualityOfService qos,
109 CAAddress_t *addressInfo,
110 CAConnectivityType_t connectivityType,
114 CreateObserveHeaderOption (CAHeaderOption_t **caHdrOpt,
115 OCHeaderOption *ocHdrOpt,
117 uint8_t observeFlag);
119 GetObserveHeaderOption (uint32_t * observationOption,
120 CAHeaderOption_t *options,
121 uint8_t * numOptions);
124 #endif //OC_OBSERVE_H