1 /*
2  * Copyright (C) 2015-2018 Alibaba Group Holding Limited
3  */
4 
5 #ifndef __COAP_OBSERVE_H__
6 #define __COAP_OBSERVE_H__
7 #include "CoAPExport.h"
8 #include "CoAPMessage.h"
9 #include "CoAPResource.h"
10 #include "iotx_coap_internal.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif /* __cplusplus */
15 
16 typedef struct {
17     NetworkAddr remote;
18     unsigned char token[COAP_MSG_MAX_TOKEN_LEN];
19     unsigned char tokenlen;
20     unsigned char ctype;
21     CoAPResource *p_resource_of_interest;
22     unsigned int observer_sequence_num;
23     CoAPMessageCode msg_type;
24     struct list_head obslist;
25 } CoapObserver;
26 
27 typedef struct {
28     NetworkAddr remote;
29     unsigned char token[COAP_MSG_MAX_TOKEN_LEN];
30     unsigned char tokenlen;
31     CoAPSendMsgHandler callback;
32     unsigned int max_age;
33     struct list_head obslist;
34     void *userdata;
35 } CoAPObservable;
36 
37 int CoAPObsServer_init(CoAPContext *context, unsigned char obs_maxcount);
38 int CoAPObsServer_deinit(CoAPContext *context);
39 
40 int CoAPObsServer_add(CoAPContext *context, const char *path,
41                       NetworkAddr *remote, CoAPMessage *request);
42 int CoapObsServer_delete(CoAPContext *context, NetworkAddr *remote,
43                          CoAPResource *resource);
44 int CoapObsServerAll_delete(CoAPContext *context, NetworkAddr *remote);
45 
46 int CoAPObsServer_notify(CoAPContext *context, const char *path,
47                          unsigned char *payload, unsigned short payloadlen,
48                          CoAPDataEncrypt handler);
49 
50 int CoAPObsClient_init(CoAPContext *context, unsigned char obs_maxcount);
51 int CoAPObsClient_deinit(CoAPContext *context);
52 int CoAPObsClient_add(CoAPContext *context, CoAPMessage *message,
53                       NetworkAddr *remote, CoAPSendNode *sendnode);
54 int CoAPObsClient_delete(CoAPContext *context, CoAPMessage *message);
55 
56 #ifdef __cplusplus
57 }
58 #endif /* __cplusplus */
59 
60 #endif
61