Repo Merge: Moving resource API down a directory
[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 #define OC_RESOURCE_OBSERVE_REGISTER     (0)
27 #define OC_RESOURCE_OBSERVE_DEREGISTER   (1)
28 #define OC_RESOURCE_NO_OBSERVE           (2)
29
30 #define MAX_OBSERVER_FAILED_COMM         (2)
31 #define MAX_OBSERVER_NON_COUNT           (3)
32
33 #define OC_OBSERVER_NOT_INTERESTED       (0)
34 #define OC_OBSERVER_STILL_INTERESTED     (1)
35 #define OC_OBSERVER_FAILED_COMM          (2)
36
37 /* This information is stored for each registerd observer */
38 typedef struct ResourceObserver {
39     // Observation Identifier for request
40     OCObservationId observeId;
41     // URI of observed resource
42     unsigned char *resUri;
43     // Query
44     unsigned char *query;
45     // CoAP token for the observe request
46     OCCoAPToken token;
47     // Resource handle
48     OCResource *resource;
49     // IP address & port of client registered for observe
50     OCDevAddr *addr;
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 OCStackResult OCObserverStatus(OCCoAPToken * token, uint8_t status);
64
65 OCStackResult ProcessObserveRequest (OCResource *resource, OCRequest *request);
66
67 OCStackResult SendObserverNotification (OCMethod method, OCResource *resPtr, uint32_t maxAge,
68         OCQualityOfService qos);
69
70 void DeleteObserverList();
71
72 OCStackResult GenerateObserverId (OCObservationId *observationId);
73
74 OCStackResult AddObserver (const char         *resUri,
75                            const char         *query,
76                            OCObservationId    obsId,
77                            OCCoAPToken        *token,
78                            OCDevAddr          *addr,
79                            OCResource         *resHandle,
80                            OCQualityOfService qos);
81
82 OCStackResult DeleteObserverUsingToken (OCCoAPToken * token);
83
84 ResourceObserver* GetObserverUsingToken (const OCCoAPToken * token);
85
86 ResourceObserver* GetObserverUsingId (const OCObservationId observeId);
87
88 #endif //OC_OBSERVE_H