Revise directory structure
[platform/core/connectivity/asp-manager.git] / src / asp-service.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
17 /*****************************************************************************
18  * Standard headers
19  *****************************************************************************/
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <time.h>
25
26 /*****************************************************************************
27  * System headers
28  *****************************************************************************/
29
30 #include <glib.h>
31 #include <gio/gio.h>
32
33 #include<dlog.h>
34
35 /*****************************************************************************
36  * Application Service Platform Daemon headers
37  *****************************************************************************/
38 #include "asp-manager-util.h"
39 #include "asp-manager-gdbus.h"
40 #include "asp-service.h"
41 #include "asp-session.h"
42 #include "asp-tech.h"
43
44 #include "generated-code.h"
45
46 /*****************************************************************************
47  * Macros and Typedefs
48  *****************************************************************************/
49
50 /* TODO : define service data structure */
51
52 /*****************************************************************************
53  * Global Variables
54  *****************************************************************************/
55
56 /* TODO : define local memory for service data structure */
57
58 /*****************************************************************************
59  * Local Functions Definition
60  *****************************************************************************/
61
62 static guint64 asp_service_search_id;
63
64 gint32 asp_service_init()
65 {
66         __ASP_LOG_FUNC_ENTER__;
67         gint32 result = 0;
68         asp_service_search_id = 0;
69
70         __ASP_LOG_FUNC_EXIT__;
71         return result;
72 }
73
74 gint32 asp_service_deinit()
75 {
76         __ASP_LOG_FUNC_ENTER__;
77         gint32 result = 0;
78
79         __ASP_LOG_FUNC_EXIT__;
80         return result;
81 }
82
83 gint32 asp_service_advertise(asp_service_advertise_s *service, gint32 replace)
84 {
85         __ASP_LOG_FUNC_ENTER__;
86         gint32 discovery_tech = service->discovery_tech;
87         gint32 result = 0;
88
89         ASP_LOGD("Discovery tech %x", discovery_tech);
90         result = asp_tech_advertise(discovery_tech, service, replace);
91         if (result < 0) {
92                 /* TODO */
93                 /* error handling */
94
95         }
96
97         __ASP_LOG_FUNC_EXIT__;
98         return result;
99 }
100
101 gint32 asp_service_cancel_advertise(asp_service_advertise_s *service)
102 {
103         __ASP_LOG_FUNC_ENTER__;
104         gint32 discovery_tech = service->discovery_tech;
105         gint32 result = 0;
106
107         ASP_LOGD("Discovery tech %x", discovery_tech);
108         result = asp_tech_cancel_advertise(discovery_tech, service);
109         if (result < 0) {
110                 /* TODO */
111                 /* error handling */
112
113         }
114
115         __ASP_LOG_FUNC_EXIT__;
116         return result;
117 }
118
119 gint32 asp_service_seek(asp_service_seek_s *service, guint64 *search_id)
120 {
121         __ASP_LOG_FUNC_ENTER__;
122         gint32 discovery_tech = service->discovery_tech;
123         gint32 result = 0;
124
125         ASP_LOGD("Discovery tech %x", discovery_tech);
126         service->search_id = asp_service_search_id;
127         result = asp_tech_seek(discovery_tech, service);
128         if (result < 0) {
129                 /* TODO */
130                 /* error handling */
131
132         }
133
134         *search_id = service->search_id;
135         asp_service_search_id++;
136
137         __ASP_LOG_FUNC_EXIT__;
138         return result;
139 }
140
141 gint32 asp_service_cancel_seek(asp_service_seek_s *service)
142 {
143         __ASP_LOG_FUNC_ENTER__;
144         gint32 discovery_tech = service->discovery_tech;
145         gint32 result = 0;
146
147         ASP_LOGD("Discovery tech %x", discovery_tech);
148         result = asp_tech_cancel_seek(discovery_tech, service);
149         if (result < 0) {
150                 /* TODO */
151                 /* error handling */
152
153         }
154
155         __ASP_LOG_FUNC_EXIT__;
156         return result;
157 }
158
159 gint32 asp_service_notify_advertise_status(guint32 adv_id,
160                 asp_service_advertise_status_e status,
161                 asp_service_advertise_reason_e reason)
162 {
163         __ASP_LOG_FUNC_ENTER__;
164         gint32 result = 0;
165
166         asp_manager_gdbus_notify_advertise_status(adv_id, (guint8)status, (gint32)reason);
167
168         __ASP_LOG_FUNC_EXIT__;
169         return result;
170 }
171
172 gint32 asp_service_notify_search_result(guint32 search_id,
173                 const gchar *service_mac, const gchar *service_device_name,
174                 guint32 adv_id, const gchar *instance_name,
175                 GHashTable *service_info_map, asp_service_status_e service_status)
176 {
177         __ASP_LOG_FUNC_ENTER__;
178         gint32 result = 0;
179
180         asp_manager_gdbus_notify_search_result(search_id,
181                         service_mac,
182                         service_device_name,
183                         adv_id,
184                         instance_name,
185                         service_info_map,
186                         (guint8)service_status);
187
188         __ASP_LOG_FUNC_EXIT__;
189         return result;
190 }