Allow multiple presence
[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 #include <gio/gio.h>
23
24 #include <octypes.h>
25
26 #include "iotcon.h"
27 #include "ic-dbus.h"
28
29 #define ICD_IOTY_COAP "coap://"
30 #define ICD_IOTY_COAPS "coaps://"
31
32 #define ICD_MULTICAST_ADDRESS "224.0.1.187:5683"
33
34 /* TODO Define Tizen Information Resource(uri, resource type) */
35 #define ICD_IOTY_TIZEN_INFO_URI "/org/tizen/iot/d"
36 #define ICD_IOTY_TIZEN_INFO_TYPE "org.tizen.iot.d"
37
38 #define ICD_IOTY_TIZEN_INFO_DEVICE_NAME "device_name"
39 #define ICD_IOTY_TIZEN_INFO_TIZEN_DEVICE_ID "tizen_device_id"
40
41 typedef struct {
42         int64_t signal_number;
43         char *bus_name;
44 } icd_sig_ctx_s;
45
46 typedef struct {
47         OCDoHandle handle;
48         int client_count;
49 } icd_presence_handle_info;
50
51 enum {
52         ICD_CRUD_GET,
53         ICD_CRUD_PUT,
54         ICD_CRUD_POST,
55         ICD_CRUD_DELETE,
56         ICD_DEVICE_INFO,
57         ICD_PLATFORM_INFO,
58         ICD_TIZEN_INFO,
59 };
60
61 void icd_ioty_csdk_lock();
62
63 void icd_ioty_csdk_unlock();
64
65 GThread* icd_ioty_init(const char *addr, unsigned short port);
66
67 void icd_ioty_deinit(GThread *thread);
68
69 OCResourceHandle icd_ioty_register_resource(const char *uri_path,
70                 const char* const* res_types, int ifaces, int properties);
71
72 int icd_ioty_unregister_resource(OCResourceHandle handle);
73
74 int icd_ioty_bind_interface(OCResourceHandle handle, iotcon_interface_e iface);
75
76 int icd_ioty_bind_type(OCResourceHandle handle, const char *resource_type);
77
78 int icd_ioty_bind_resource(OCResourceHandle parent, OCResourceHandle child);
79
80 int icd_ioty_unbind_resource(OCResourceHandle parent, OCResourceHandle child);
81
82 int icd_ioty_notify(OCResourceHandle handle, GVariant *msg, GVariant *observers);
83
84 int icd_ioty_send_response(GVariant *resp);
85
86 int icd_ioty_find_resource(const char *host_address, int conn_type,
87                 const char *resource_type, int64_t signal_number, const char *bus_name);
88
89 void icd_ioty_complete(int type, GDBusMethodInvocation *invocation, GVariant *value);
90 void icd_ioty_complete_error(int type, GDBusMethodInvocation *invocation, int ret_val);
91
92 gboolean icd_ioty_get(icDbus *object, GDBusMethodInvocation *invocation,
93                 GVariant *resource, GVariant *query);
94
95 gboolean icd_ioty_put(icDbus *object, GDBusMethodInvocation *invocation,
96                 GVariant *resource, GVariant *repr, GVariant *query);
97
98 gboolean icd_ioty_post(icDbus *object, GDBusMethodInvocation *invocation,
99                 GVariant *resource, GVariant *repr, GVariant *query);
100
101 gboolean icd_ioty_delete(icDbus *object, GDBusMethodInvocation *invocation,
102                 GVariant *resource);
103
104 OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_type,
105                 GVariant *query, int64_t signal_number, const char *bus_name);
106
107 int icd_ioty_observer_stop(OCDoHandle handle, GVariant *options);
108
109 int icd_ioty_get_info(int type, const char *host_address, int conn_type,
110                 int64_t signal_number, const char *bus_name);
111
112 int icd_ioty_set_device_info();
113 int icd_ioty_set_platform_info();
114 int icd_ioty_set_tizen_info();
115
116 gboolean icd_ioty_get_tizen_info(icDbus *object, GDBusMethodInvocation *invocation,
117                 const gchar *host_address, int conn_type);
118
119 int icd_ioty_tizen_info_get_property(char **device_name, char **tizen_device_id);
120
121 OCDoHandle icd_ioty_presence_table_get_handle(const char *host_address);
122
123 OCDoHandle icd_ioty_subscribe_presence(const char *host_address, int conn_type,
124                 const char *resource_type);
125
126 int icd_ioty_unsubscribe_presence(OCDoHandle handle, const char *host_address);
127
128 int icd_ioty_start_presence(unsigned int time_to_live);
129
130 int icd_ioty_stop_presence();
131
132 static inline int icd_ioty_convert_error(int ret)
133 {
134         switch (ret) {
135         case OC_STACK_NO_MEMORY:
136                 return IOTCON_ERROR_OUT_OF_MEMORY;
137         case OC_STACK_NO_RESOURCE:
138                 return IOTCON_ERROR_NO_DATA;
139         default:
140                 break;
141         }
142         return IOTCON_ERROR_IOTIVITY;
143 }
144
145 #endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_H__*/