} while (0)
-#define RETURN_IF_DBUS_TYPE_MISMATCH(parameters, str) do { \
- DEBUG_PARAM_TYPE(parameters); \
- DEBUG_PARAMS(parameters); \
- if (g_strcmp0(g_variant_get_type_string(parameters), str)) { \
- STC_LOGE("Dbus type not matching, do not process"); \
- __STC_LOG_FUNC_EXIT__; \
- return; \
- } \
-} while (0)
-
typedef void(*dbus_dict_cb)(const char *key, GVariant *value,
void *user_data);
#define STC_PLUGIN_FILEPATH "/usr/lib/stc-manager-plugin.so"
+#include "stc-plugin.h"
+
void stc_manager_plugin_init(void);
void stc_manager_plugin_deinit(void);
int stc_send_restriction_message_to_net_popup(const char *content,
const char *type, const char *app_id, const char *iftype, const char *limit);
+int stc_register_state_changed_cb(stc_s *stc,
+ stc_plugin_app_state_changed_cb cb,
+ void *data);
+int stc_deregister_state_changed_cb(stc_s *stc);
+
#endif /* __STC_MANAGER_PLUGIN_H__ */
STC_CONTINUE = 1, /**< continue */
} stc_cb_ret_e;
+typedef enum {
+ STC_CMD_NONE,
+ STC_CMD_SET_FOREGRD,
+ STC_CMD_SET_BACKGRD,
+ STC_CMD_SET_APP_LAUNCHED,
+ STC_CMD_SET_SERVICE_LAUNCHED,
+ STC_CMD_SET_TERMINATED,
+ STC_CMD_MAX_ELEM
+} stc_cmd_type_e;
+
/**
* @brief Monitored application types
*/
#define __STC_PLUGIN_H__
#include <glib.h>
+#include "stc-error.h"
+#include "stc-manager.h"
+
+typedef stc_error_e (*stc_plugin_app_state_changed_cb)(stc_cmd_type_e cmd,
+ pid_t pid,
+ const gchar *app_id,
+ const gchar *pkg_id,
+ stc_app_type_e app_type);
typedef struct {
int(*send_restriction_message_to_net_popup) (const char *,
- const char *, const char *, const char *, const char *);
+ const char *,
+ const char *,
+ const char *,
+ const char *);
int(*send_warn_message_to_net_popup) (const char *,
- const char *, const char *, const char *, const char *);
+ const char *,
+ const char *,
+ const char *,
+ const char *);
+ int (*register_state_changed_cb) (stc_s *stc,
+ stc_plugin_app_state_changed_cb cb,
+ void *data);
+ int (*deregister_state_changed_cb) (stc_s *stc);
} stc_plugin_s;
#endif /* __STC_PLUGIN_H__ */
Name: stc-manager
Summary: STC(Smart Traffic Control) manager
-Version: 0.0.29
+Version: 0.0.30
Release: 0
Group: Network & Connectivity/Other
License: Apache-2.0
ENDFOREACH(flag)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/monitor/include)
# INCLUDE_DIRECTORIES(SRCS include)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g -Werror -fvisibility=hidden")
#include <bundle.h>
#include <bundle_internal.h>
#include <dlog.h>
+#include <gio/gio.h>
#include "stc-plugin.h"
+#include "stc-manager.h"
+#include "stc-manager-util.h"
-#ifdef USE_DLOG
-#include <dlog.h>
+/*
+ * AUL
+ */
+#define AUL_APP_STATUS_DBUS_PATH "/Org/Tizen/Aul/AppStatus"
+#define AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE "org.tizen.aul.AppStatus"
+#define AUL_APP_STATUS_BUS_NAME AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE
+
+#define AUL_APP_STATUS_DBUS_STATUS_CHANGE "AppStatusChange"
+#define AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE "(issss)"
+
+typedef struct {
+ guint sub_id;
+ const gchar *path;
+ const gchar *interface;
+ const gchar *member;
+ const gchar *param_type;
+ GDBusSignalCallback callback;
+ gpointer user_data;
+} signal_map_s;
+
+stc_error_e(*state_changed_cb)(stc_cmd_type_e cmd, pid_t pid,
+ const gchar *app_id, const gchar *pkg_id,
+ stc_app_type_e app_type);
+
+static void __stc_gdbus_handle_aul_changestate(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ __STC_LOG_FUNC_ENTER__;
+ pid_t pid;
+ stc_cmd_type_e status;
+ stc_app_type_e apptype;
+ gchar *appid, *pkgid, *statstr, *pkgtype;
+
+ if (g_strcmp0(g_variant_get_type_string(parameters),
+ AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE)) {
+ STC_LOGE("Dbus type not matching, do not process");
+ __STC_LOG_FUNC_EXIT__;
+ return;
+ }
+
+ g_variant_get(parameters, AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE,
+ &pid, &appid, &pkgid, &statstr, &pkgtype);
+
+ if (!strncmp(statstr, "fg", 2)) {
+ status = STC_CMD_SET_FOREGRD;
+ } else if (!strncmp(statstr, "bg", 2)) {
+ status = STC_CMD_SET_BACKGRD;
+ } else {
+ __STC_LOG_FUNC_EXIT__;
+ goto out;
+ }
+
+ if (!strncmp(pkgtype, "svc", 3))
+ apptype = STC_APP_TYPE_SERVICE;
+ else if (!strncmp(pkgtype, "widget", 6))
+ apptype = STC_APP_TYPE_WIDGET;
+ else if (!strncmp(pkgtype, "watch", 5))
+ apptype = STC_APP_TYPE_WATCH;
+ else
+ apptype = STC_APP_TYPE_GUI;
+
+ if (state_changed_cb)
+ state_changed_cb(status, pid, appid, pkgid, apptype);
+
+ __STC_LOG_FUNC_EXIT__;
+out:
+ FREE(appid);
+ FREE(pkgid);
+ FREE(statstr);
+ FREE(pkgtype);
+}
-#undef LOG_TAG
-#define LOG_TAG "STC_MANAGER"
+signal_map_s signal_map[] = {
+
+ /* AMD DBUS */
+ {
+ 0,
+ AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_STATUS_CHANGE,
+ AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE,
+ __stc_gdbus_handle_aul_changestate,
+ NULL
+ },
+ {
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+ }
+};
-#define STC_LOGD(format, args...) LOGD(format, ##args)
-#define STC_LOGI(format, args...) LOGI(format, ##args)
-#define STC_LOGW(format, args...) LOGW(format, ##args)
-#define STC_LOGE(format, args...) LOGE(format, ##args)
-#define __STC_LOG_FUNC_ENTER__ LOGD("Enter")
-#define __STC_LOG_FUNC_EXIT__ LOGD("Quit")
+static stc_error_e __ground_status_monitor_init(stc_s *stc)
+{
+ guint i = 0;
+
+ ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
+
+ for (i = 0; signal_map[i].member != NULL; i++) {
+ signal_map[i].sub_id =
+ g_dbus_connection_signal_subscribe(stc->connection,
+ NULL,
+ signal_map[i].interface,
+ signal_map[i].member,
+ signal_map[i].path,
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ signal_map[i].callback,
+ signal_map[i].user_data,
+ NULL);
+ STC_LOGI("Successfully subscribed [%s] signal",
+ signal_map[i].member);
+ }
+
+ return STC_ERROR_NONE;
+}
-#else /* USE_DLOG */
+static stc_error_e __ground_status_monitor_deinit(stc_s *stc)
+{
+ guint i = 0;
-#define STC_LOGD(format, args...)
-#define STC_LOGI(format, args...)
-#define STC_LOGW(format, args...)
-#define STC_LOGE(format, args...)
+ ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
-#define __STC_LOG_FUNC_ENTER__
-#define __STC_LOG_FUNC_EXIT__
+ for (i = 0; signal_map[i].member != NULL; i++) {
+ g_dbus_connection_signal_unsubscribe(stc->connection,
+ signal_map[i].sub_id);
+ signal_map[i].sub_id = 0;
+ STC_LOGD("Successfully unsubscribed [%s] signal",
+ signal_map[i].member);
+ }
-#endif /* USE_DLOG */
+ return STC_ERROR_NONE;
+}
static int __stc_send_warn_message_to_net_popup(const char *content,
const char *type, const char *app_id, const char *iftype, const char *warn)
return ret;
}
+static int __register_state_changed_cb(stc_s *stc,
+ stc_plugin_app_state_changed_cb cb,
+ void *data)
+{
+ state_changed_cb = cb;
+ __ground_status_monitor_init(stc);
+
+ return 0;
+}
+
+int __deregister_state_changed_cb(stc_s *stc)
+{
+ state_changed_cb = NULL;
+ __ground_status_monitor_deinit(stc);
+ return 0;
+}
API stc_plugin_s stc_plugin = {
.send_warn_message_to_net_popup =
__stc_send_warn_message_to_net_popup,
.send_restriction_message_to_net_popup =
- __stc_send_restriction_message_to_net_popup
+ __stc_send_restriction_message_to_net_popup,
+ .register_state_changed_cb = __register_state_changed_cb,
+ .deregister_state_changed_cb = __deregister_state_changed_cb
};
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __STC_APP_GROUND_STATUS_H__
-#define __STC_APP_GROUND_STATUS_H__
-
-#include "stc-error.h"
-#include "stc-manager.h"
-#include "stc-manager-gdbus.h"
-#include "stc-manager-util.h"
-#include "stc-monitor.h"
-
-stc_error_e stc_app_ground_status_monitor_init(stc_s *stc);
-stc_error_e stc_app_ground_status_monitor_deinit(stc_s *stc);
-
-#endif /* __STC_APP_GROUND_STATUS_H__ */
#include "stc-error.h"
#include "stc-manager.h"
-#include "stc-manager-gdbus.h"
#include "stc-manager-util.h"
#include "stc-monitor.h"
-typedef enum {
- STC_CMD_NONE,
- STC_CMD_SET_FOREGRD,
- STC_CMD_SET_BACKGRD,
- STC_CMD_SET_APP_LAUNCHED,
- STC_CMD_SET_SERVICE_LAUNCHED,
- STC_CMD_SET_TERMINATED,
- STC_CMD_MAX_ELEM
-} stc_cmd_type_e;
-
stc_error_e stc_manager_app_status_changed(stc_cmd_type_e cmd,
pid_t pid,
gchar *app_id,
#include <glib.h>
#include "stc-error.h"
#include "stc-manager.h"
-#include "stc-manager-gdbus.h"
#include "stc-manager-util.h"
#define IMSI_LENGTH 16
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "stc-app-lifecycle.h"
-#include "stc-app-ground-status.h"
-
-/*
- * AUL
- */
-#define AUL_APP_STATUS_DBUS_PATH "/Org/Tizen/Aul/AppStatus"
-#define AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE "org.tizen.aul.AppStatus"
-#define AUL_APP_STATUS_BUS_NAME AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE
-
-#define AUL_APP_STATUS_DBUS_STATUS_CHANGE "AppStatusChange"
-#define AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE "(issss)"
-
-typedef struct {
- guint sub_id;
- const gchar *path;
- const gchar *interface;
- const gchar *member;
- const gchar *param_type;
- GDBusSignalCallback callback;
- gpointer user_data;
-} signal_map_s;
-
-static void __stc_gdbus_handle_aul_changestate(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- __STC_LOG_FUNC_ENTER__;
- pid_t pid;
- stc_cmd_type_e status;
- stc_app_type_e apptype;
- gchar *appid, *pkgid, *statstr, *pkgtype;
-
- RETURN_IF_DBUS_TYPE_MISMATCH(parameters,
- AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE);
-
- g_variant_get(parameters, AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE,
- &pid, &appid, &pkgid, &statstr, &pkgtype);
-
- if (!strncmp(statstr, "fg", 2)) {
- status = STC_CMD_SET_FOREGRD;
- } else if (!strncmp(statstr, "bg", 2)) {
- status = STC_CMD_SET_BACKGRD;
- } else {
- __STC_LOG_FUNC_EXIT__;
- goto handle_error;
- }
-
- if (!strncmp(pkgtype, "svc", 3))
- apptype = STC_APP_TYPE_SERVICE;
- else if (!strncmp(pkgtype, "widget", 6))
- apptype = STC_APP_TYPE_WIDGET;
- else if (!strncmp(pkgtype, "watch", 5))
- apptype = STC_APP_TYPE_WATCH;
- else
- apptype = STC_APP_TYPE_GUI;
-
- stc_manager_app_status_changed(status, pid, appid, pkgid, apptype);
-
- __STC_LOG_FUNC_EXIT__;
-handle_error:
- FREE(appid);
- FREE(pkgid);
- FREE(statstr);
- FREE(pkgtype);
-}
-
-signal_map_s signal_map[] = {
-
- /* AMD DBUS */
- {
- 0,
- AUL_APP_STATUS_DBUS_PATH,
- AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
- AUL_APP_STATUS_DBUS_STATUS_CHANGE,
- AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE,
- __stc_gdbus_handle_aul_changestate,
- NULL
- },
- {
- 0,
- NULL,
- NULL,
- NULL,
- NULL
- }
-};
-
-stc_error_e stc_app_ground_status_monitor_init(stc_s *stc)
-{
- guint i = 0;
- ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
-
- for (i = 0; signal_map[i].member != NULL; i++) {
- signal_map[i].sub_id =
- stc_manager_gdbus_subscribe_signal(stc->connection,
- NULL,
- signal_map[i].interface,
- signal_map[i].member,
- signal_map[i].path,
- NULL,
- G_DBUS_SIGNAL_FLAGS_NONE,
- signal_map[i].callback,
- signal_map[i].user_data,
- NULL);
- STC_LOGI("Successfully subscribed [%s] signal",
- signal_map[i].member);
- }
-
- return STC_ERROR_NONE;
-}
-
-stc_error_e stc_app_ground_status_monitor_deinit(stc_s *stc)
-{
- guint i = 0;
- ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
-
- for (i = 0; signal_map[i].member != NULL; i++) {
- stc_manager_gdbus_unsubscribe_signal(stc->connection,
- signal_map[i].sub_id);
- signal_map[i].sub_id = 0;
- STC_LOGD("Successfully unsubscribed [%s] signal",
- signal_map[i].member);
- }
-
- return STC_ERROR_NONE;
-}
#include <linux/cn_proc.h>
#include <glib.h>
+#include "stc-manager-gdbus.h"
#include "stc-app-lifecycle.h"
#include "helper-procfs.h"
#include <vconf/vconf.h>
#include "stc-monitor.h"
+#include "stc-manager-gdbus.h"
#include "stc-default-connection.h"
/* connman service dbus details */
#include "stc-statistics.h"
#include "stc-restriction.h"
#include "stc-default-connection.h"
-#include "stc-app-ground-status.h"
+#include "stc-manager-plugin.h"
+#include "stc-app-lifecycle.h"
static gboolean __stc_manager_gdbus_statistics_init(stc_s *stc)
{
g_dbus_object_manager_server_set_connection(stc->obj_mgr,
stc->connection);
- stc_app_ground_status_monitor_init(stc);
stc_default_connection_monitor_init(stc);
+ stc_register_state_changed_cb(stc, stc_manager_app_status_changed, NULL);
__STC_LOG_FUNC_EXIT__;
}
{
__STC_LOG_FUNC_ENTER__;
stc_s *stc = (stc_s *)stc_data;
- stc_app_ground_status_monitor_deinit(stc);
+
+ stc_deregister_state_changed_cb(stc);
stc_default_connection_monitor_deinit(stc);
+
g_bus_unown_name(stc->gdbus_owner_id);
+
stc->statistics_obj = NULL;
stc->restriction_obj = NULL;
__STC_LOG_FUNC_EXIT__;
handle_plugin = dlopen(STC_PLUGIN_FILEPATH, RTLD_NOW);
if (!handle_plugin) {
STC_LOGE("Can't load %s: %s", STC_PLUGIN_FILEPATH, dlerror());
+ __STC_LOG_FUNC_EXIT__;
return;
}
if (!stc_plugin) {
STC_LOGE("Can't load symbol: %s", dlerror());
dlclose(handle_plugin);
+ __STC_LOG_FUNC_EXIT__;
return;
}
stc_plugin_enabled = TRUE;
-
__STC_LOG_FUNC_EXIT__;
}
{
__STC_LOG_FUNC_ENTER__;
- if (!stc_plugin_enabled)
+ if (!stc_plugin_enabled) {
+ __STC_LOG_FUNC_EXIT__;
return;
+ }
stc_plugin_enabled = FALSE;
dlclose(handle_plugin);
-
__STC_LOG_FUNC_EXIT__;
}
-int stc_send_warn_message_to_net_popup(const char *content,
- const char *type, const char *app_id, const char *iftype, const char *warn)
+int stc_send_warn_message_to_net_popup(const char *content, const char *type,
+ const char *app_id, const char *iftype,
+ const char *warn)
{
__STC_LOG_FUNC_ENTER__;
if (!stc_plugin_enabled) {
STC_LOGE("Plugin wasn't enabled");
+ __STC_LOG_FUNC_EXIT__;
return 0;
}
if (!stc_plugin) {
STC_LOGE("Plugin wasn't loaded");
+ __STC_LOG_FUNC_EXIT__;
return 0;
}
- return stc_plugin->send_warn_message_to_net_popup(content, type, app_id, iftype, warn);
+ __STC_LOG_FUNC_EXIT__;
+ return stc_plugin->send_warn_message_to_net_popup(content, type, app_id,
+ iftype, warn);
}
int stc_send_restriction_message_to_net_popup(const char *content,
- const char *type, const char *app_id, const char *iftype, const char *limit)
+ const char *type,
+ const char *app_id,
+ const char *iftype,
+ const char *limit)
{
__STC_LOG_FUNC_ENTER__;
if (!stc_plugin_enabled) {
STC_LOGE("Plugin wasn't enabled");
+ __STC_LOG_FUNC_EXIT__;
return 0;
}
if (!stc_plugin) {
STC_LOGE("Plugin wasn't loaded");
+ __STC_LOG_FUNC_EXIT__;
return 0;
}
- return stc_plugin->send_restriction_message_to_net_popup(content, type, app_id, iftype, limit);
+ __STC_LOG_FUNC_EXIT__;
+ return stc_plugin->send_restriction_message_to_net_popup(content, type,
+ app_id, iftype,
+ limit);
}
+int stc_register_state_changed_cb(stc_s *stc,
+ stc_plugin_app_state_changed_cb cb,
+ void *data)
+{
+ __STC_LOG_FUNC_ENTER__;
+
+ if (!stc_plugin_enabled) {
+ __STC_LOG_FUNC_EXIT__;
+ STC_LOGE("Plugin wasn't enabled");
+ return 0;
+ }
+
+ if (!stc_plugin) {
+ STC_LOGE("Plugin wasn't loaded");
+ __STC_LOG_FUNC_EXIT__;
+ return 0;
+ }
+
+ return stc_plugin->register_state_changed_cb(stc, cb, data);
+}
+int stc_deregister_state_changed_cb(stc_s *stc)
+{
+ __STC_LOG_FUNC_ENTER__;
+
+ if (!stc_plugin_enabled) {
+ __STC_LOG_FUNC_EXIT__;
+ STC_LOGE("Plugin wasn't enabled");
+ return 0;
+ }
+
+ if (!stc_plugin) {
+ __STC_LOG_FUNC_EXIT__;
+ STC_LOGE("Plugin wasn't loaded");
+ return 0;
+ }
+ __STC_LOG_FUNC_EXIT__;
+
+ return stc_plugin->deregister_state_changed_cb(stc);
+}
#include <signal.h>
#include "stc-manager.h"
#include "stc-emulator.h"
-#include "stc-statistics.h"
-#include "stc-restriction.h"
#include "stc-manager-gdbus.h"
#include "stc-db.h"
#include "counter.h"
return;
}
- stc_app_lifecycle_monitor_deinit();
stc_monitor_deinit();
stc_deinit_db_guard();
stc_db_deinitialize();
+
stc_manager_gdbus_deinit((gpointer)g_stc);
+ stc_app_lifecycle_monitor_deinit();
stc_manager_plugin_deinit();
STC_LOGI("stc manager deinitialized");
if (err != STC_ERROR_NONE)
goto handle_error;
- stc_manager_gdbus_init((gpointer)stc);
stc_manager_plugin_init();
stc_app_lifecycle_monitor_init();
+ stc_manager_gdbus_init((gpointer)stc);
STC_LOGI("stc manager initialized");
__STC_LOG_FUNC_EXIT__;