Add systemd service
[platform/core/connectivity/asp-manager.git] / src / asp-manager-event.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 /*****************************************************************************
34  * Application Service Platform manager headers
35  *****************************************************************************/
36 #include "asp-manager.h"
37 #include "asp-service.h"
38 #include "asp-session.h"
39 #include "asp-tech.h"
40 #include "asp-manager-util.h"
41 #include "asp-manager-gdbus.h"
42
43 /*****************************************************************************
44  * Macros and Typedefs
45  *****************************************************************************/
46
47 /*****************************************************************************
48  * Global Variables
49  *****************************************************************************/
50
51 /*****************************************************************************
52  * Local Functions Definition
53  *****************************************************************************/
54
55 void __asp_process_search_result(gpointer ctx, asp_event_data *data)
56 {
57         __ASP_LOG_FUNC_ENTER__;
58
59         if (data == NULL) {
60                 ASP_LOGE("Invalid parameters");
61                 return;
62         }
63
64         asp_service_notify_search_result(
65                         data->search_result.search_id,
66                         data->search_result.service_mac,
67                         data->search_result.device_name,
68                         data->search_result.advertisement_id,
69                         data->search_result.instance_name,
70                         data->search_result.service_info,
71                         data->search_result.service_status);
72
73         __ASP_LOG_FUNC_EXIT__;
74         return;
75 }
76
77 void __asp_process_search_terminated(void *ctx, asp_event_data *data)
78 {
79         __ASP_LOG_FUNC_ENTER__;
80
81         __ASP_LOG_FUNC_EXIT__;
82         return;
83 }
84
85 static struct {
86         const gint32 event_id;
87         void (*function) (gpointer ctx, asp_event_data *data);
88 } asp_event_map[] = {
89                 {
90                                 ASP_EVENT_NONE,
91                                 NULL
92                 },
93                 {
94                                 ASP_EVENT_SEARCH_RESULT,
95                                 __asp_process_search_result,
96                 },
97                 {
98                                 ASP_EVENT_SEARCH_TERMINATED,
99                                 __asp_process_search_terminated,
100                 },
101                 {
102                                 ASP_EVENT_MAX,
103                                 NULL
104                 }
105 };
106
107 void asp_manager_event(gpointer ctx, asp_event_type_e event, asp_event_data *data)
108 {
109         __ASP_LOG_FUNC_ENTER__;
110
111         if (event > ASP_EVENT_NONE &&
112                         event < ASP_EVENT_MAX)
113                  asp_event_map[event].function(ctx, data);
114         else
115                 ASP_LOGE("Invalid event");
116
117         __ASP_LOG_FUNC_EXIT__;
118         return;
119 }