Make local handle for event loop
[platform/core/api/connection.git] / src / connection_mptcp.c
1 /*
2  * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License")
5 {
6 }
7
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <glib.h>
21
22 #include "connection_extension.h"
23 #include "net_connection_private.h"
24 #include "net_connection_mptcp_private.h"
25
26 EXPORT_API int connection_mptcp_is_supported(connection_h connection, bool* supported)
27 {
28         if (!(_connection_check_handle_validity(connection))) {
29                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
30                 return CONNECTION_ERROR_INVALID_PARAMETER;
31         }
32
33         *supported = _connection_libnet_mptcp_supported(connection);
34         return CONNECTION_ERROR_NONE;
35 }
36
37 EXPORT_API int connection_mptcp_enable(connection_h connection, connection_mptcp_enable_e enable)
38 {
39         // check MPTCP support
40         if (_connection_libnet_mptcp_supported(connection) == FALSE) {
41                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");     //LCOV_EXCL_LINE
42                 return CONNECTION_ERROR_NOT_SUPPORTED;  //LCOV_EXCL_LINE
43         }
44
45         if (!(_connection_check_handle_validity(connection))) {
46                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
47                 return CONNECTION_ERROR_INVALID_PARAMETER;
48         }
49
50         if (enable <= CONNECTION_MPTCP_DISABLE
51                         || enable > CONNECTION_MPTCP_ENABLE_SOCKOPT) {
52                 CONNECTION_LOG(CONNECTION_ERROR, "Use connection_mptcp_disable()");     //LCOV_EXCL_LINE
53                 return CONNECTION_ERROR_INVALID_PARAMETER;      //LCOV_EXCL_LINE
54         }
55
56         return _connection_libnet_mptcp_enable(connection, enable);
57 }
58
59 EXPORT_API int connection_mptcp_disable(connection_h connection)
60 {
61         // check MPTCP support
62         if (_connection_libnet_mptcp_supported(connection) == FALSE) {
63                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");     //LCOV_EXCL_LINE
64                 return CONNECTION_ERROR_NOT_SUPPORTED;  //LCOV_EXCL_LINE
65         }
66
67         if (!(_connection_check_handle_validity(connection))) {
68                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
69                 return CONNECTION_ERROR_INVALID_PARAMETER;
70         }
71
72         return _connection_libnet_mptcp_enable(connection, CONNECTION_MPTCP_DISABLE);
73 }
74
75 EXPORT_API int connection_mptcp_get_enabled(connection_h connection, connection_mptcp_enable_e* enable)
76 {
77         // check MPTCP support
78         if (_connection_libnet_mptcp_supported(connection) == FALSE) {
79                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");     //LCOV_EXCL_LINE
80                 return CONNECTION_ERROR_NOT_SUPPORTED;  //LCOV_EXCL_LINE
81         }
82
83         if (!(_connection_check_handle_validity(connection))) {
84                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
85                 return CONNECTION_ERROR_INVALID_PARAMETER;
86         }
87
88         if (enable == NULL) {
89                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");  //LCOV_EXCL_LINE
90                 return CONNECTION_ERROR_INVALID_PARAMETER;      //LCOV_EXCL_LINE
91         }
92
93         return _connection_libnet_mptcp_get_enabled(connection, enable);
94 }
95
96
97 EXPORT_API int connection_mptcp_set_path_manager(connection_h connection, connection_mptcp_path_manager_e pm)
98 {
99         // check MPTCP support
100         if (_connection_libnet_mptcp_supported(connection) == FALSE) {
101                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");     //LCOV_EXCL_LINE
102                 return CONNECTION_ERROR_NOT_SUPPORTED;  //LCOV_EXCL_LINE
103         }
104
105         if (!(_connection_check_handle_validity(connection))) {
106                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
107                 return CONNECTION_ERROR_INVALID_PARAMETER;
108         }
109
110         return _connection_libnet_mptcp_set_path_manager(connection, pm);
111 }
112
113 EXPORT_API int connection_mptcp_get_path_manager(connection_h connection, connection_mptcp_path_manager_e* pm)
114 {
115         // check MPTCP support
116         if (_connection_libnet_mptcp_supported(connection) == FALSE) {
117                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");     //LCOV_EXCL_LINE
118                 return CONNECTION_ERROR_NOT_SUPPORTED;  //LCOV_EXCL_LINE
119         }
120
121         if (!(_connection_check_handle_validity(connection))) {
122                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
123                 return CONNECTION_ERROR_INVALID_PARAMETER;
124         }
125
126         if (pm == NULL) {
127                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
128                 return CONNECTION_ERROR_INVALID_PARAMETER;
129         }
130
131         return _connection_libnet_mptcp_get_path_manager(connection, pm);
132 }
133
134
135 EXPORT_API int connection_mptcp_set_scheduler(connection_h connection, connection_mptcp_scheduler_e scheduler)
136 {
137         // check MPTCP support
138         if (_connection_libnet_mptcp_supported(connection) == FALSE) {
139                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");     //LCOV_EXCL_LINE
140                 return CONNECTION_ERROR_NOT_SUPPORTED;  //LCOV_EXCL_LINE
141         }
142
143         if (!(_connection_check_handle_validity(connection))) {
144                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
145                 return CONNECTION_ERROR_INVALID_PARAMETER;
146         }
147
148         return _connection_libnet_mptcp_set_scheduler(connection, scheduler);
149 }
150
151 EXPORT_API int connection_mptcp_get_scheduler(connection_h connection, connection_mptcp_scheduler_e* scheduler)
152 {
153         // check MPTCP support
154         if (_connection_libnet_mptcp_supported(connection) == FALSE) {
155                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");     //LCOV_EXCL_LINE
156                 return CONNECTION_ERROR_NOT_SUPPORTED;  //LCOV_EXCL_LINE
157         }
158
159         if (!(_connection_check_handle_validity(connection))) {
160                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
161                 return CONNECTION_ERROR_INVALID_PARAMETER;
162         }
163
164         if (scheduler == NULL) {
165                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
166                 return CONNECTION_ERROR_INVALID_PARAMETER;
167         }
168
169         return _connection_libnet_mptcp_get_scheduler(connection, scheduler);
170 }
171
172