tizen 2.3.1 release
[kernel/api/system-resource.git] / src / network / join.c
1 /*
2  * resourced
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 /**
21  * @file join.c
22  * @desc Implement Performance API. Joining performance control.
23  *    Entity for creation cgroup
24  */
25
26 #include <resourced.h>
27
28 #include "const.h"
29 #include "edbus-handler.h"
30 #include "macro.h"
31 #include "trace.h"
32
33 #ifdef NETWORK_SERVICE_OFF
34 API resourced_ret_c join_app_performance(const char *app_id, const pid_t pid)
35 {
36         return RESOURCED_ERROR_NONE;
37 }
38
39 #else
40
41 static resourced_ret_c send_join_message(const char *interface,
42         const char *format_str, char *params[])
43 {
44         DBusError err;
45         DBusMessage *msg;
46         resourced_ret_c ret_val;
47         int ret, i = 0;
48
49         do {
50                 msg = dbus_method_sync(BUS_NAME, RESOURCED_PATH_NETWORK,
51                                        RESOURCED_INTERFACE_NETWORK,
52                                        interface,
53                                        format_str, params);
54                 if (msg)
55                         break;
56                 _E("Re-try to sync DBUS message, err_count : %d", i);
57         } while (i++ < RETRY_MAX);
58
59         if (!msg) {
60                 _E("Failed to sync DBUS message.");
61                 return RESOURCED_ERROR_FAIL;
62         }
63
64         dbus_error_init(&err);
65
66         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val,
67                                     DBUS_TYPE_INVALID);
68
69         if (ret == FALSE) {
70                 _E("no message : [%s:%s]\n", err.name, err.message);
71                 ret_val = RESOURCED_ERROR_FAIL;
72         }
73
74         dbus_message_unref(msg);
75         dbus_error_free(&err);
76
77         return ret_val;
78 }
79
80 API resourced_ret_c join_app_performance(const char *app_id, const pid_t pid)
81 {
82         char *params[2];
83
84         if (!app_id)
85                 return RESOURCED_ERROR_INVALID_PARAMETER;
86
87         serialize_params(params, ARRAY_SIZE(params), app_id, pid);
88
89         return send_join_message(RESOURCED_NETWORK_JOIN_NET_STAT, "sd", params);
90 }
91 #endif