(ACR) Integrate notify_list and notify_all
[platform/core/iot/iotcon.git] / daemon / icd-ioty.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef __IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_H__
17 #define __IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_H__
18
19 #include <stdio.h>
20 #include <stdint.h>
21 #include <glib.h>
22
23 #include <octypes.h>
24
25 #include "iotcon.h"
26
27 #define ICD_IOTY_COAP "coap://"
28 #define ICD_IOTY_COAPS "coaps://"
29
30 typedef struct {
31         unsigned int signum;
32         char *bus_name;
33 } icd_sig_ctx_s;
34
35 enum {
36         ICD_CRUD_GET,
37         ICD_CRUD_PUT,
38         ICD_CRUD_POST,
39         ICD_CRUD_DELETE,
40         ICD_DEVICE_INFO,
41         ICD_PLATFORM_INFO,
42 };
43
44 void icd_ioty_csdk_lock();
45
46 void icd_ioty_csdk_unlock();
47
48 GThread* icd_ioty_init(const char *addr, unsigned short port);
49
50 void icd_ioty_deinit(GThread *thread);
51
52 OCResourceHandle icd_ioty_register_resource(const char *uri_path,
53                 const char* const* res_types, int ifaces, uint8_t properties);
54
55 int icd_ioty_unregister_resource(OCResourceHandle handle);
56
57 int icd_ioty_bind_interface(OCResourceHandle handle, iotcon_interface_e iface);
58
59 int icd_ioty_bind_type(OCResourceHandle handle, const char *resource_type);
60
61 int icd_ioty_bind_resource(OCResourceHandle parent, OCResourceHandle child);
62
63 int icd_ioty_unbind_resource(OCResourceHandle parent, OCResourceHandle child);
64
65 int icd_ioty_notify(OCResourceHandle handle, GVariant *msg, GVariant *observers);
66
67 int icd_ioty_send_response(GVariant *resp);
68
69 int icd_ioty_find_resource(const char *host_address, const char *resource_type,
70                 unsigned int signal_number, const char *bus_name);
71
72 void icd_ioty_complete(int type, GDBusMethodInvocation *invocation, GVariant *value);
73 void icd_ioty_complete_error(int type, GDBusMethodInvocation *invocation, int ret_val);
74
75 gboolean icd_ioty_get(icDbus *object, GDBusMethodInvocation *invocation,
76                 GVariant *resource, GVariant *query);
77
78 gboolean icd_ioty_put(icDbus *object, GDBusMethodInvocation *invocation,
79                 GVariant *resource, GVariant *repr, GVariant *query);
80
81 gboolean icd_ioty_post(icDbus *object, GDBusMethodInvocation *invocation,
82                 GVariant *resource, GVariant *repr, GVariant *query);
83
84 gboolean icd_ioty_delete(icDbus *object, GDBusMethodInvocation *invocation,
85                 GVariant *resource);
86
87 OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_type, GVariant *query,
88                 unsigned int signal_number, const char *bus_name);
89
90 int icd_ioty_observer_stop(OCDoHandle handle, GVariant *options);
91
92 int icd_ioty_register_device_info(GVariant *value);
93
94 int icd_ioty_register_platform_info(GVariant *value);
95
96 int icd_ioty_get_info(int type, const char *host_address, unsigned int signal_number,
97                 const char *bus_name);
98
99 OCDoHandle icd_ioty_subscribe_presence(const char *host_address,
100                 const char *resource_type, unsigned int signal_number, const char *bus_name);
101
102 int icd_ioty_unsubscribe_presence(OCDoHandle handle);
103
104 int icd_ioty_start_presence(unsigned int time_to_live);
105
106 int icd_ioty_stop_presence();
107
108 static inline int icd_ioty_convert_error(int ret)
109 {
110         switch (ret) {
111         case OC_STACK_NO_MEMORY:
112                 return IOTCON_ERROR_OUT_OF_MEMORY;
113         case OC_STACK_NO_RESOURCE:
114                 return IOTCON_ERROR_NO_DATA;
115         default:
116                 break;
117         }
118         return IOTCON_ERROR_IOTIVITY;
119 }
120
121 #endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_H__*/