CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(stc-manager C)
+PROJECT(stc-manager C CXX)
SET(PACKAGE ${PROJECT_NAME})
SET(INTERFACES "${CMAKE_SOURCE_DIR}/interfaces")
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(plugin)
+
+IF(BUILD_GTESTS)
+ ADD_SUBDIRECTORY(unittest)
+ENDIF(BUILD_GTESTS)
#define STC_DBUS_SERVICE_PATH "/net/stc"
#define STC_DBUS_SERVICE_STATISTICS_PATH "/net/stc/statistics"
#define STC_DBUS_SERVICE_RESTRICTION_PATH "/net/stc/restriction"
-#define STC_DBUS_SERVICE_QUOTA_PATH "/net/stc/quota"
+#define STC_DBUS_SERVICE_MANAGER_PATH "/net/stc/manager"
#define STC_DBUS_REPLY_ERROR_NONE(invocation) \
g_dbus_method_invocation_return_value((invocation), \
const gchar *signal_name,
GVariant *parameters);
+gboolean handle_manager_stop(StcManager *object,
+ GDBusMethodInvocation *invocation);
+
#endif /* __STC_MANAGER_GDBUS_H__ */
/**
* @desc Set of the options.
- * version - contains structure version
* wifi - enable/disable wifi, STC_DB_OPTION_UNDEF to leave option as is
* datacall - enable/disable datacall, STC_DB_OPTION_UNDEF to leave option as is
* datausage_timer - set period of the updating data from the kernel,
* STC_DB_OPTION_UNDEF to leave option as is
*/
typedef struct {
- unsigned char version;
stc_option_state_e wifi;
stc_option_state_e datacall;
time_t datausage_timer;
gpointer statistics_obj;
gpointer restriction_obj;
+ gpointer manager_obj;
GDBusObjectManagerServer *obj_mgr;
GDBusConnection *connection;
} stc_s;
stc_s *stc_get_manager(void);
+void stc_stop_manager(void);
#endif /* __STC_MANAGER__ */
--- /dev/null
+<node>
+ <interface name="net.stc.manager">
+ <method name='Stop'>
+ <arg type='i' name='error_code' direction='out'/>
+ </method>
+ </interface>
+</node>
<arg type='i' name='error_code' direction='out'/>
</method>
+ <method name='Stop'>
+ <arg type='i' name='error_code' direction='out'/>
+ </method>
+
<signal name='WarnThresholdCrossed'>
<arg type='s' name='app_id'/>
</signal>
Name: stc-manager
Summary: STC(Smart Traffic Control) manager
-Version: 0.0.42
+Version: 0.0.43
Release: 0
Group: Network & Connectivity/Other
License: Apache-2.0
BuildRequires: python
BuildRequires: python-xml
+%if 0%{?gtests:1}
+BuildRequires: pkgconfig(gmock)
+%endif
+
%description
A smart traffic control manager to manage traffic counting and bandwidth limitation
-DENABLE_DATABASE=%{enable_database} \
-DDATABASE_FULL_PATH=%{database_full_path} \
-DENABLE_STATISTICS=%{enable_statistics} \
- -DENABLE_RESTRICTION=%{enable_restriction}
+ -DENABLE_RESTRICTION=%{enable_restriction} \
+ -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0} \
+ -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0}
make %{?_smp_mflags}
%config(noreplace) %attr(660, root, root) %{database_full_path}-journal
%endif
+%if 0%{?gtests:1}
+%{_bindir}/gtest*
+%endif
+
%files plugin
%manifest %{name}.manifest
%attr(644, -,-) %{_datadir}/icons/*.png
INSTALL(FILES ${DATA_DIR}/traffic_db.sql DESTINATION /usr/share)
ENDIF()
+IF(BUILD_GTESTS)
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fpic -Wall -Werror-implicit-function-declaration")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fprofile-arcs -ftest-coverage")
+ELSE(BUILD_GTESTS)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fpic -Wall -Werror-implicit-function-declaration -fvisibility=hidden")
-SET(ARM_CFLAGS "${ARM_CFLAGS} -mapcs -mabi=aapcs-linux -msoft-float -Uarm -fpic")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+ENDIF(BUILD_GTESTS)
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
ADD_DEFINITIONS("-DUSE_DLOG")
ADD_DEFINITIONS("-DDATABASE_FULL_PATH=\"${DATABASE_FULL_PATH}\"")
+IF(BUILD_GTESTS)
+ ADD_DEFINITIONS(-DTIZEN_GTESTS)
+ENDIF(BUILD_GTESTS)
ADD_CUSTOM_COMMAND(
WORKING_DIRECTORY
--c-namespace Stc
--c-generate-object-manager
--generate-docbook generated-code-docs
+ ${INTERFACES}/stcmanager-iface-manager.xml
${INTERFACES}/stcmanager-iface-restriction.xml
${INTERFACES}/stcmanager-iface-statistics.xml
COMMENT "Generating GDBus .c/.h")
static sqlite3 *database;
+//LCOV_EXCL_START
static int __stc_db_busy(void *user, int attempts)
{
__STC_LOG_FUNC_ENTER__;
__STC_LOG_FUNC_EXIT__;
return 1;
}
+//LCOV_EXCL_STOP
stc_error_e stc_db_initialize_once(void)
{
int res = 0;
int retry_count = 0;
if (database != NULL) {
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_NONE;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_NONE; //LCOV_EXCL_LINE
}
do {
res = sqlite3_open(DATABASE_FULL_PATH, &database);
if (res != SQLITE_OK) {
- STC_LOGD("Retry[%d] opening database %s: %s\n",
+ STC_LOGD("Retry[%d] opening database %s: %s\n", //LCOV_EXCL_LINE
++retry_count, DATABASE_FULL_PATH,
- sqlite3_errmsg(database));
+ sqlite3_errmsg(database)); //LCOV_EXCL_LINE
} else {
break;
}
} while (retry_count <= MAX_DB_RETRY_COUNT);
if (res != SQLITE_OK) {
- STC_LOGE("Can't open database %s: %s\n", DATABASE_FULL_PATH,
+ STC_LOGE("Can't open database %s: %s\n", DATABASE_FULL_PATH, //LCOV_EXCL_LINE
sqlite3_errmsg(database));
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_DB_FAILED;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
STC_LOGD("Successfully opened database");
res = sqlite3_exec(database, "PRAGMA locking_mode = NORMAL", 0, 0, 0);
if (res != SQLITE_OK) {
- STC_LOGE("Can't set locking mode %s, skip set busy handler.",
+ STC_LOGE("Can't set locking mode %s, skip set busy handler.", //LCOV_EXCL_LINE
sqlite3_errmsg(database));
- sqlite3_close(database);
- database = NULL;
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_DB_FAILED;
+ sqlite3_close(database); //LCOV_EXCL_LINE
+ database = NULL; //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
/* Set how many times we'll repeat our attempts for sqlite_step */
if (sqlite3_busy_handler(database, __stc_db_busy, NULL)
!= SQLITE_OK)
- STC_LOGE("Couldn't set busy handler!");
+ STC_LOGE("Couldn't set busy handler!"); //LCOV_EXCL_LINE
__STC_LOG_FUNC_EXIT__;
return STC_ERROR_NONE;
}
+//LCOV_EXCL_START
sqlite3 *stc_db_get_database(void)
{
if (database == NULL)
return database;
}
+//LCOV_EXCL_STOP
stc_error_e stc_db_initialize(void)
{
return STC_ERROR_NONE;
handle_error:
- stc_db_deinitialize();
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_DB_FAILED;
+ stc_db_deinitialize(); //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
gboolean stc_db_deinitialize(void)
{
__STC_LOG_FUNC_ENTER__;
if (database == NULL) {
- __STC_LOG_FUNC_EXIT__;
- return TRUE;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return TRUE; //LCOV_EXCL_LINE
}
table_statistics_finalize();
static guint erase_timer = 0;
static int db_entries = 0;
+//LCOV_EXCL_START
static void __change_db_entries_num_num(int num)
{
__STC_LOG_FUNC_ENTER__;
__STC_LOG_FUNC_EXIT__;
return TRUE;
}
+//LCOV_EXCL_STOP
stc_error_e stc_init_db_guard(void)
{
erase_timer = g_timeout_add_seconds(ERASE_TIMER_INTERVAL,
__erase_func_cb, NULL);
if (erase_timer == 0) {
- STC_LOGE("Failed to create timer");
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_FAIL;
+ STC_LOGE("Failed to create timer"); //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
__STC_LOG_FUNC_EXIT__;
time_t to;
} stc_db_tm_interval_s;
-typedef enum {
- STC_DB_CON_PERIOD_UNKNOWN, /**< Undefined period */
- STC_DB_CON_PERIOD_LAST_RECEIVED_DATA, /**< Last received data */
- STC_DB_CON_PERIOD_LAST_SENT_DATA, /**< Last sent data */
- STC_DB_CON_PERIOD_TOTAL_RECEIVED_DATA, /**< Total received data */
- STC_DB_CON_PERIOD_TOTAL_SENT_DATA, /**< Total sent data */
- STC_DB_CON_PERIOD_LAST_ELEM
-} stc_db_connection_period_type;
-
/*
* General structure containing information for storing
* app_id - package name as unique application identifier
} table_statistics_info;
typedef struct {
- unsigned char version;
char *app_id;
char *subscriber_id;
stc_iface_type_e iftype;
stc_db_tm_interval_s *interval;
- stc_db_connection_period_type connection_state;
} table_statistics_reset_rule;
typedef struct {
- unsigned char version;
time_t from;
time_t to;
stc_iface_type_e iftype;
static int initialized;
if (initialized) {
- __STC_LOG_FUNC_EXIT__;
- return SQLITE_OK;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return SQLITE_OK; //LCOV_EXCL_LINE
}
PREPARE_DELETE(delete_counter, DELETE_COUNTER);
static int initialized;
if (initialized) {
- __STC_LOG_FUNC_EXIT__;
- return SQLITE_OK;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return SQLITE_OK; //LCOV_EXCL_LINE
}
PREPARE_SELECT(select_counter, SELECT_COUNTER);
static int initialized;
if (initialized) {
- __STC_LOG_FUNC_EXIT__;
- return SQLITE_OK;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return SQLITE_OK; //LCOV_EXCL_LINE
}
PREPARE_UPDATE(update_counter, UPDATE_COUNTER);
do {
rc = sqlite3_step(stmt);
+ //LCOV_EXCL_START
switch (rc) {
case SQLITE_DONE:
break;
error_code = STC_ERROR_DB_FAILED;
}
+ //LCOV_EXCL_STOP
} while (rc == SQLITE_ROW);
handle_error:
return error_code;
}
+//LCOV_EXCL_START
stc_error_e table_counters_update_counters(const table_counters_info *info)
{
stc_error_e error_code = STC_ERROR_NONE;
sqlite3_reset(stmt);
return error_code;
}
+//LCOV_EXCL_STOP
stc_error_e table_counters_delete(uint64_t restriction_id)
{
DB_ACTION(sqlite3_bind_int64(stmt, 1, restriction_id));
if (sqlite3_step(stmt) != SQLITE_DONE) {
- STC_LOGE("Failed to delete counter: %s\n",
+ STC_LOGE("Failed to delete counter: %s\n", //LCOV_EXCL_LINE
sqlite3_errmsg(stc_db_get_database()));
- error_code = STC_ERROR_DB_FAILED;
- goto handle_error;
+ error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+ goto handle_error; //LCOV_EXCL_LINE
}
STC_LOGD("Counter deleted for restriction_id [%llu]", restriction_id);
stc_error_e error_code = STC_ERROR_NONE;
if (db == NULL) {
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_FAIL;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
DB_ACTION(__prepare_delete(db));
static int initialized;
if (initialized) {
- __STC_LOG_FUNC_EXIT__;
- return SQLITE_OK;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return SQLITE_OK; //LCOV_EXCL_LINE
}
PREPARE_DELETE(delete_restrictions, DELETE_RESTRICTIONS);
static int initialized;
if (initialized) {
- __STC_LOG_FUNC_EXIT__;
- return SQLITE_OK;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return SQLITE_OK; //LCOV_EXCL_LINE
}
PREPARE_SELECT(select_restriction, SELECT_RESTRICTIONS);
static int initialized;
if (initialized) {
- __STC_LOG_FUNC_EXIT__;
- return SQLITE_OK;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return SQLITE_OK; //LCOV_EXCL_LINE
}
PREPARE_UPDATE(update_net_restrictions, UPDATE_NET_RESTRICTIONS);
static int initialized;
if (initialized) {
- __STC_LOG_FUNC_EXIT__;
- return SQLITE_OK;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return SQLITE_OK; //LCOV_EXCL_LINE
}
PREPARE_UPDATE(insert_net_restrictions, INSERT_NET_RESTRICTIONS);
sqlite3_stmt *stmt = select_restriction_per_app;
if (!app_id) {
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_DB_FAILED;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
DB_ACTION(sqlite3_bind_text(stmt, 1, app_id, -1,
data.restriction_id = sqlite3_column_int64(stmt, 8);
if (restriction_cb(&data, user_data) == STC_CANCEL)
- rc = SQLITE_DONE;
+ rc = SQLITE_DONE; //LCOV_EXCL_LINE
break;
case SQLITE_ERROR:
default:
- STC_LOGE("Failed to enumerate restrictions: %s\n",
+ STC_LOGE("Failed to enumerate restrictions: %s\n", //LCOV_EXCL_LINE
sqlite3_errmsg(stc_db_get_database()));
- __STC_LOG_FUNC_EXIT__;
- error_code = STC_ERROR_DB_FAILED;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
} while (rc == SQLITE_ROW);
data.restriction_id = sqlite3_column_int64(stmt, 8);
if (restriction_cb(&data, user_data) == STC_CANCEL)
- rc = SQLITE_DONE;
+ rc = SQLITE_DONE; //LCOV_EXCL_LINE
break;
case SQLITE_ERROR:
default:
- STC_LOGE("Failed to enumerate restrictions: %s\n",
+ STC_LOGE("Failed to enumerate restrictions: %s\n", //LCOV_EXCL_LINE
sqlite3_errmsg(stc_db_get_database()));
- __STC_LOG_FUNC_EXIT__;
- error_code = STC_ERROR_DB_FAILED;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
} while (rc == SQLITE_ROW);
bool state_subscriber_id = 0;
if (state == NULL) {
- STC_LOGE("Please provide valid argument!");
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_INVALID_PARAMETER;
+ STC_LOGE("Please provide valid argument!"); //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
*state = STC_RESTRICTION_UNKNOWN;
break;
case SQLITE_ERROR:
default:
- STC_LOGE("Can't perform sql query: %s \n%s",
+ STC_LOGE("Can't perform sql query: %s \n%s", //LCOV_EXCL_LINE
SELECT_RESTRICTION_STATE,
sqlite3_errmsg(stc_db_get_database()));
- error_code = STC_ERROR_DB_FAILED;
+ error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
handle_error:
SQLITE_TRANSIENT));
if (sqlite3_step(stmt) != SQLITE_DONE) {
- STC_LOGE("Failed to remove restrictions by network interface %s\n",
+ STC_LOGE("Failed to remove restrictions by network interface %s\n", //LCOV_EXCL_LINE
sqlite3_errmsg(stc_db_get_database()));
- error_code = STC_ERROR_DB_FAILED;
- goto handle_error;
+ error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+ goto handle_error; //LCOV_EXCL_LINE
}
STC_LOGD("Restriction deleted for app_id [%s]", app_id);
break;
case SQLITE_ERROR:
default:
- STC_LOGE("Failed to get restriction id: %s\n",
+ STC_LOGE("Failed to get restriction id: %s\n", //LCOV_EXCL_LINE
sqlite3_errmsg(stc_db_get_database()));
}
sqlite3_stmt *stmt = insert_net_restrictions;
if (!info) {
- error_code = STC_ERROR_INVALID_PARAMETER;
- goto handle_error;
+ error_code = STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ goto handle_error; //LCOV_EXCL_LINE
}
__get_restriction_id(info);
DB_ACTION(sqlite3_bind_int64(stmt, 9, info->restriction_id));
if (sqlite3_step(stmt) != SQLITE_DONE) {
- STC_LOGE("Failed to set network restriction: %s\n",
+ STC_LOGE("Failed to set network restriction: %s\n", //LCOV_EXCL_LINE
sqlite3_errmsg(stc_db_get_database()));
- error_code = STC_ERROR_DB_FAILED;
- goto handle_error;
+ error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+ goto handle_error; //LCOV_EXCL_LINE
}
if (info->restriction_id) {
stc_error_e error_code = STC_ERROR_NONE;
if (db == NULL) {
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_FAIL;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
DB_ACTION(__prepare_delete(db));
static int initialized;
if (initialized) {
- __STC_LOG_FUNC_EXIT__;
- return SQLITE_OK;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return SQLITE_OK; //LCOV_EXCL_LINE
}
PREPARE_DELETE(delete_query[0], DELETE_ALL);
static int initialized;
if (initialized) {
- __STC_LOG_FUNC_EXIT__;
- return SQLITE_OK;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return SQLITE_OK; //LCOV_EXCL_LINE
}
PREPARE_SELECT(select_for_period, SELECT_FOR_PERIOD);
static int initialized;
if (initialized) {
- __STC_LOG_FUNC_EXIT__;
- return SQLITE_OK;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return SQLITE_OK; //LCOV_EXCL_LINE
}
PREPARE_INSERT(update_statistics_query, INSERT_VALUES);
return *details_stms[stm_index];
}
+//LCOV_EXCL_START
stc_error_e table_statistics_reset_first_n_entries(int num)
{
__STC_LOG_FUNC_ENTER__;
sqlite3_reset(delete_query[4]);
return error_code;
}
+//LCOV_EXCL_STOP
stc_error_e table_statistics_reset(const table_statistics_reset_rule *rule)
{
__STC_LOG_FUNC_ENTER__;
sqlite3_stmt *stmt;
stc_error_e error_code = STC_ERROR_NONE;
- int pos = 1;/* running through positions where to
+ int pos = 1; /* running through positions where to
bind parameters in the query */
if (!rule || !rule->interval) {
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_INVALID_PARAMETER;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
/* pick a statement depending on parameters.
DB_ACTION(sqlite3_bind_int64(stmt, pos++, rule->interval->to));
if (sqlite3_step(stmt) != SQLITE_DONE) {
- STC_LOGE("Failed to drop collected statistics.");
- error_code = STC_ERROR_DB_FAILED;
- __STC_LOG_FUNC_EXIT__;
- goto handle_error;
+ STC_LOGE("Failed to drop collected statistics."); //LCOV_EXCL_LINE
+ error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ goto handle_error; //LCOV_EXCL_LINE
}
STC_LOGD("Entry deleted successfully.");
memset(&data, 0, sizeof(data));
if (!rule || !info_cb) {
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_INVALID_PARAMETER;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
/* pick a statement depending on parameters */
}
if (info_cb(&data, user_data) == STC_CANCEL)
- rc = SQLITE_DONE;/* emulate end of data */
+ rc = SQLITE_DONE; //LCOV_EXCL_LINE
__STC_LOG_FUNC_EXIT__;
break;
case SQLITE_DONE:
break;
case SQLITE_ERROR:
default:
- error_code = STC_ERROR_DB_FAILED;
- __STC_LOG_FUNC_EXIT__;
- break;
+ error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ break; //LCOV_EXCL_LINE
}
} while (rc == SQLITE_ROW);
sqlite3_stmt *stmt;
stc_error_e error_code = STC_ERROR_NONE;
int rc;
- int pos = 1;/* running through positions
+ int pos = 1; /* running through positions
where to bind parameters in the query */
stc_db_tm_interval_s interval;
memset(&data, 0, sizeof(data));
if (!rule || !info_cb) {
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_INVALID_PARAMETER;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
/* pick a statement depending on parameters.
}
if (info_cb(&data, user_data) == STC_CANCEL)
- rc = SQLITE_DONE; /* emulate end of data */
+ rc = SQLITE_DONE; //LCOV_EXCL_LINE
__STC_LOG_FUNC_EXIT__;
break;
case SQLITE_DONE:
break;
case SQLITE_ERROR:
default:
- error_code = STC_ERROR_DB_FAILED;
- __STC_LOG_FUNC_EXIT__;
- break;
+ error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ break; //LCOV_EXCL_LINE
}
} while (rc == SQLITE_ROW);
stat->rcv_count = 0;
stat->snd_count = 0;
if (sqlite3_step(stmt) != SQLITE_DONE) {
- STC_LOGE("Failed to record appstat. %s",
+ STC_LOGE("Failed to record appstat. %s", //LCOV_EXCL_LINE
sqlite3_errmsg(stc_db_get_database()));
- error_code = STC_ERROR_DB_FAILED;
- __STC_LOG_FUNC_EXIT__;
- goto handle_error;
+ error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ goto handle_error; //LCOV_EXCL_LINE
}
STC_LOGD("App stat recorded [%s]", stat->app_id);
stc_error_e error_code = STC_ERROR_NONE;
if (db == NULL) {
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_DB_FAILED;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
DB_ACTION(__prepare_delete(db));
{
if (mkdir(cgroup_full_path,
S_IRUSR | S_IWUSR | S_IRGRP) < 0)
- return -errno;
+ return -errno; //LCOV_EXCL_LINE
return 0;
}
int ret;
if (pid <= 0) {
- STC_LOGE("try to write empty pid to %s", cgroup_full_path);
- return STC_ERROR_NO_DATA;
+ STC_LOGE("try to write empty pid to %s", cgroup_full_path); //LCOV_EXCL_LINE
+ return STC_ERROR_NO_DATA; //LCOV_EXCL_LINE
}
ret = cgroup_write_node_uint32(cgroup_full_path, CGROUP_FILE_NAME,
return cgroup_write_pid_fullpath(buf, pid);
}
+//LCOV_EXCL_START
stc_error_e cgroup_write_pidtree(const char *cgroup_subsystem,
const char *cgroup_name, const int pid)
{
fclose(f);
return STC_ERROR_NONE;
}
+//LCOV_EXCL_STOP
int cgroup_write_node_uint32(const char *cgroup_name,
const char *file_name, uint32_t value)
snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
if (STC_DEBUG_LOG)
- STC_LOGD("cgroup_buf %s, value %d\n", buf, value);
+ STC_LOGD("cgroup_buf %s, value %d\n", buf, value); //LCOV_EXCL_LINE
return fwrite_uint(buf, value);
}
snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
if (STC_DEBUG_LOG)
- STC_LOGD("cgroup_buf %s, string %s\n", buf, string);
+ STC_LOGD("cgroup_buf %s, string %s\n", buf, string); //LCOV_EXCL_LINE
return fwrite_str(buf, string);
}
ret = fread_uint(buf, value);
if (STC_DEBUG_LOG)
- STC_LOGD("cgroup_buf %s, value %d\n", buf, *value);
+ STC_LOGD("cgroup_buf %s, value %d\n", buf, *value); //LCOV_EXCL_LINE
return ret;
}
if (parentdir && !strncmp(parentdir, DEFAULT_CGROUP,
sizeof(DEFAULT_CGROUP))) {
- ret = mount("tmpfs", DEFAULT_CGROUP, "tmpfs",
+ ret = mount("tmpfs", DEFAULT_CGROUP, "tmpfs", //LCOV_EXCL_LINE
MS_REMOUNT|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME,
"mode=755");
if (ret < 0) {
- STC_LOGE("Fail to RW mount cgroup directory. Can't make %s cgroup", cgroup_name);
- return STC_ERROR_FAIL;
+ STC_LOGE("Fail to RW mount cgroup directory. Can't make %s cgroup", cgroup_name); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
cgroup_remount = true;
}
cgroup_name, errno);
if (cgroup_remount) {
- ret = mount("tmpfs", DEFAULT_CGROUP, "tmpfs",
+ ret = mount("tmpfs", DEFAULT_CGROUP, "tmpfs", //LCOV_EXCL_LINE
MS_REMOUNT|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME|MS_RDONLY,
"mode=755");
if (ret < 0)
- STC_LOGD("Fail to RO mount");
+ STC_LOGD("Fail to RO mount"); //LCOV_EXCL_LINE
}
}
iptables_rule_s *rule)
{
if (builder == NULL || rule == NULL)
- return;
+ return; //LCOV_EXCL_LINE
g_variant_builder_add(builder, "{sv}", RULE_CHAIN,
g_variant_new_string(rule->chain));
params);
if (message == NULL) {
- STC_LOGE("Failed to invoke dbus method");
- return STC_ERROR_FAIL;
+ STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
g_variant_get(message, "(i)", &result);
params);
if (message == NULL) {
- STC_LOGE("Failed to invoke dbus method");
- return STC_ERROR_FAIL;
+ STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
g_variant_get(message, "(i)", &result);
params);
if (message == NULL) {
- STC_LOGE("Failed to invoke dbus method");
- return STC_ERROR_FAIL;
+ STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
g_variant_get(message, "(i)", &result);
params);
if (message == NULL) {
- STC_LOGE("Failed to invoke dbus method");
- return STC_ERROR_FAIL;
+ STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
g_variant_get(message, "(i)", &result);
g_variant_new("(s)", chain));
if (message == NULL) {
- STC_LOGE("Failed to invoke dbus method");
- return STC_ERROR_FAIL;
+ STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
g_variant_get(message, "(i)", &result);
g_variant_new("(s)", chain));
if (message == NULL) {
- STC_LOGE("Failed to invoke dbus method");
- return STC_ERROR_FAIL;
+ STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
g_variant_get(message, "(i)", &result);
g_variant_new("(s)", chain));
if (message == NULL) {
- STC_LOGE("Failed to invoke dbus method");
- return STC_ERROR_FAIL;
+ STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
g_variant_get(message, "(i)", &result);
g_variant_new("(s)", chain));
if (message == NULL) {
- STC_LOGE("Failed to invoke dbus method");
- return STC_ERROR_FAIL;
+ STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
g_variant_get(message, "(i)", &result);
g_variant_new("(s)", chain));
if (message == NULL) {
- STC_LOGE("Failed to invoke dbus method");
- return STC_ERROR_FAIL;
+ STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
g_variant_get(message, "(i)", &result);
g_variant_new("(s)", chain));
if (message == NULL) {
- STC_LOGE("Failed to invoke dbus method");
- return STC_ERROR_FAIL;
+ STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
g_variant_get(message, "(i)", &result);
stc_s *stc = stc_get_manager();
if (!stc || !stc->connection)
- return STC_ERROR_INVALID_PARAMETER;
+ return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
ret = __iptables_rule_add(stc->connection, rule);
if (ret != STC_ERROR_NONE)
- goto done;
+ goto done; //LCOV_EXCL_LINE
ret = __ip6tables_rule_add(stc->connection, rule);
done:
stc_s *stc = stc_get_manager();
if (!stc || !stc->connection)
- return STC_ERROR_INVALID_PARAMETER;
+ return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
ret = __iptables_rule_remove(stc->connection, rule);
if (ret != STC_ERROR_NONE)
- goto done;
+ goto done; //LCOV_EXCL_LINE
ret = __ip6tables_rule_remove(stc->connection, rule);
done:
stc_s *stc = stc_get_manager();
if (!stc || !stc->connection)
- return STC_ERROR_INVALID_PARAMETER;
+ return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
ret = __iptables_flush_chain(stc->connection, STC_IN_CHAIN);
if (ret != STC_ERROR_NONE)
- goto done;
+ goto done; //LCOV_EXCL_LINE
ret = __iptables_flush_chain(stc->connection, STC_OUT_CHAIN);
if (ret != STC_ERROR_NONE)
- goto done;
+ goto done; //LCOV_EXCL_LINE
ret = __iptables_flush_chain(stc->connection, STC_FRWD_CHAIN);
if (ret != STC_ERROR_NONE)
- goto done;
+ goto done; //LCOV_EXCL_LINE
ret = __ip6tables_flush_chain(stc->connection, STC_IN_CHAIN);
if (ret != STC_ERROR_NONE)
- goto done;
+ goto done; //LCOV_EXCL_LINE
ret = __ip6tables_flush_chain(stc->connection, STC_OUT_CHAIN);
if (ret != STC_ERROR_NONE)
- goto done;
+ goto done; //LCOV_EXCL_LINE
ret = __ip6tables_flush_chain(stc->connection, STC_FRWD_CHAIN);
done:
stc_s *stc = stc_get_manager();
if (!stc || !stc->connection) {
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_INVALID_PARAMETER;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
ret = __iptables_add_chain(stc->connection, STC_IN_CHAIN);
if (ret != STC_ERROR_NONE) {
- __STC_LOG_FUNC_EXIT__;
- goto done;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
ret = __iptables_add_chain(stc->connection, STC_OUT_CHAIN);
if (ret != STC_ERROR_NONE) {
- __STC_LOG_FUNC_EXIT__;
- goto done;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
ret = __iptables_add_chain(stc->connection, STC_FRWD_CHAIN);
if (ret != STC_ERROR_NONE) {
- __STC_LOG_FUNC_EXIT__;
- goto done;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
ret = __ip6tables_add_chain(stc->connection, STC_IN_CHAIN);
if (ret != STC_ERROR_NONE) {
- __STC_LOG_FUNC_EXIT__;
- goto done;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
ret = __ip6tables_add_chain(stc->connection, STC_OUT_CHAIN);
if (ret != STC_ERROR_NONE) {
- __STC_LOG_FUNC_EXIT__;
- goto done;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
ret = __ip6tables_add_chain(stc->connection, STC_FRWD_CHAIN);
if (ret != STC_ERROR_NONE) {
- __STC_LOG_FUNC_EXIT__;
- goto done;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
ret = __iptables_add_chain_jump_rule("INPUT", STC_IN_CHAIN);
if (ret != STC_ERROR_NONE) {
- __STC_LOG_FUNC_EXIT__;
- goto done;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
ret = __iptables_add_chain_jump_rule("OUTPUT", STC_OUT_CHAIN);
if (ret != STC_ERROR_NONE) {
- __STC_LOG_FUNC_EXIT__;
- goto done;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
ret = __iptables_add_chain_jump_rule("FORWARD", STC_FRWD_CHAIN);
stc_s *stc = stc_get_manager();
if (!stc || !stc->connection) {
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_INVALID_PARAMETER;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
ret = __iptables_remove_chain(stc->connection, STC_IN_CHAIN);
if (ret != STC_ERROR_NONE) {
- __STC_LOG_FUNC_EXIT__;
- goto done;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
ret = __iptables_remove_chain(stc->connection, STC_OUT_CHAIN);
if (ret != STC_ERROR_NONE) {
- __STC_LOG_FUNC_EXIT__;
- goto done;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
ret = __iptables_remove_chain(stc->connection, STC_FRWD_CHAIN);
if (ret != STC_ERROR_NONE) {
- __STC_LOG_FUNC_EXIT__;
- goto done;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
ret = __ip6tables_remove_chain(stc->connection, STC_IN_CHAIN);
if (ret != STC_ERROR_NONE) {
- __STC_LOG_FUNC_EXIT__;
- goto done;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
ret = __ip6tables_remove_chain(stc->connection, STC_OUT_CHAIN);
if (ret != STC_ERROR_NONE) {
- __STC_LOG_FUNC_EXIT__;
- goto done;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
ret = __ip6tables_remove_chain(stc->connection, STC_FRWD_CHAIN);
uint32_t classid = STC_RESERVED_CLASSID_MAX;
int ret = fread_uint(CUR_CLASSID_PATH, &classid);
if (ret < 0)
- STC_LOGI("Can not read current classid");
+ STC_LOGI("Can not read current classid"); //LCOV_EXCL_LINE
classid += 1;
ret = fwrite_uint(CUR_CLASSID_PATH, ++classid);
if (ret < 0)
- STC_LOGE("Can not write classid");
+ STC_LOGE("Can not write classid"); //LCOV_EXCL_LINE
return classid;
}
int ret = cgroup_read_node_uint32(buf, CLASSID_FILE_NAME, &classid);
if (ret < 0)
- STC_LOGE("Can't read classid from cgroup %s", buf);
+ STC_LOGE("Can't read classid from cgroup %s", buf); //LCOV_EXCL_LINE
return classid;
}
uint32_t classid = STC_RESERVED_CLASSID_MAX;
ret = fwrite_uint(CUR_CLASSID_PATH, classid);
if (ret < 0) {
- STC_LOGE("Can not init current classid");
- return STC_ERROR_FAIL;
+ STC_LOGE("Can not init current classid"); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
}
const char *path_to_net_cgroup_dir = NULL;
if (app_id == NULL) {
- STC_LOGE("app_id must be not empty");
- return STC_UNKNOWN_CLASSID;
+ STC_LOGE("app_id must be not empty"); //LCOV_EXCL_LINE
+ return STC_UNKNOWN_CLASSID; //LCOV_EXCL_LINE
}
if (!strcmp(app_id, STC_BACKGROUND_APP_ID))
/* just read */
if (!create)
- classid = __get_classid_from_cgroup(path_to_net_cgroup_dir,
+ classid = __get_classid_from_cgroup(path_to_net_cgroup_dir, //LCOV_EXCL_LINE
app_id);
if (classid != STC_UNKNOWN_CLASSID)
ret = __place_classid_to_cgroup(path_to_net_cgroup_dir,
(char *)app_id, &classid, NULL);
if (ret)
- goto handle_error;
+ goto handle_error; //LCOV_EXCL_LINE
return classid;
handle_error:
- STC_LOGE("error_code: [%d]", ret);
- return STC_UNKNOWN_CLASSID;
+ STC_LOGE("error_code: [%d]", ret); //LCOV_EXCL_LINE
+ return STC_UNKNOWN_CLASSID; //LCOV_EXCL_LINE
}
stc_error_e place_pids_to_net_cgroup(const int pid, const char *app_id)
snprintf(child_buf, sizeof(child_buf), PROC_TASK_CHILDREN, pid, pid);
if (app_id == NULL) {
- STC_LOGE("package name must be not empty");
- return STC_ERROR_INVALID_PARAMETER;
+ STC_LOGE("package name must be not empty"); //LCOV_EXCL_LINE
+ return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
if (!strcmp(app_id, STC_BACKGROUND_APP_ID))
else if (strstr(app_id, STC_BACKGROUND_APP_SUFFIX))
path_to_net_cgroup_dir = BACKGROUND_CGROUP_NETWORK;
else
- path_to_net_cgroup_dir = FOREGROUND_CGROUP_NETWORK;
+ path_to_net_cgroup_dir = FOREGROUND_CGROUP_NETWORK; //LCOV_EXCL_LINE
if (access(child_buf, F_OK)) {
if (STC_DEBUG_LOG)
- STC_LOGD("%s of %s is not existed", child_buf, app_id);
+ STC_LOGD("%s of %s is not existed", child_buf, app_id); //LCOV_EXCL_LINE
return cgroup_write_pid(path_to_net_cgroup_dir, app_id, pid);
}
- return cgroup_write_pidtree(path_to_net_cgroup_dir, app_id, pid);
+ return cgroup_write_pidtree(path_to_net_cgroup_dir, app_id, pid); //LCOV_EXCL_LINE
}
int ret = STC_ERROR_NONE;
struct genl *req = MALLOC0(struct genl, 1);
if (req == NULL) {
- STC_LOGE("Failed allocate memory to genl request message");
- return STC_ERROR_OUT_OF_MEMORY;
+ STC_LOGE("Failed allocate memory to genl request message"); //LCOV_EXCL_LINE
+ return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
}
prepare_netlink_msg(req, NFNL_MSG_ACCT_NEW, NLM_F_CREATE | NLM_F_ACK);
add_string_attr(req, counter->name, NFACCT_NAME);
if (STC_DEBUG_LOG)
- STC_LOGD("counter name %s", counter->name);
+ STC_LOGD("counter name %s", counter->name); //LCOV_EXCL_LINE
/* padding */
add_uint64_attr(req, 0, NFACCT_PKTS);
add_uint64_attr(req, 0, NFACCT_BYTES);
+ //LCOV_EXCL_START
if (counter->quota) {
STC_LOGD("quota bytes %"PRId64, counter->quota);
NFACCT_FLAGS);
add_uint64_attr(req, htobe64(counter->quota), NFACCT_QUOTA);
}
+ //LCOV_EXCL_STOP
ret = send_nfacct_request(counter->carg->sock, req);
FREE(req);
int ret = STC_ERROR_NONE;
struct genl *req = MALLOC0(struct genl, 1);
if (req == NULL) {
- STC_LOGE("Failed allocate memory to genl request message");
- return STC_ERROR_OUT_OF_MEMORY;
+ STC_LOGE("Failed allocate memory to genl request message"); //LCOV_EXCL_LINE
+ return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
}
if (STC_DEBUG_LOG)
- STC_LOGD("send remove request for %s", counter->name);
+ STC_LOGD("send remove request for %s", counter->name); //LCOV_EXCL_LINE
prepare_netlink_msg(req, NFNL_MSG_ACCT_DEL, NLM_F_ACK);
add_string_attr(req, counter->name, NFACCT_NAME);
int flag = !name ? NLM_F_DUMP : 0;
struct genl *req = MALLOC0(struct genl, 1);
if (req == NULL) {
- STC_LOGE("Failed allocate memory to genl request message");
- return STC_ERROR_OUT_OF_MEMORY;
+ STC_LOGE("Failed allocate memory to genl request message"); //LCOV_EXCL_LINE
+ return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
}
prepare_netlink_msg(req, get_type, flag);
cnt->intend = NFACCT_BLOCK;
break;
case 't':
- cnt->intend = NFACCT_TETH_COUNTER;
- break;
+ cnt->intend = NFACCT_TETH_COUNTER; //LCOV_EXCL_LINE
+ break; //LCOV_EXCL_LINE
default:
return false;
}
STRING_SAVE_COPY(cnt->name, cnt_name);
+ //LCOV_EXCL_START
if (cnt->intend == NFACCT_TETH_COUNTER) {
char ifname_buf[MAX_IFACE_LENGTH];
int ifname_len;
cnt->classid = STC_TETHERING_APP_CLASSID;
return true;
}
+ //LCOV_EXCL_STOP
io_part = strtok_r(name, "_", &save_ptr);
if (io_part != NULL)
return STC_IN_CHAIN;
else if (iotype == NFACCT_COUNTER_OUT)
return STC_OUT_CHAIN;
- else if (iotype == NFACCT_COUNTER_FORWARD)
- return STC_FRWD_CHAIN;
+ else if (iotype == NFACCT_COUNTER_FORWARD) //LCOV_EXCL_LINE
+ return STC_FRWD_CHAIN; //LCOV_EXCL_LINE
return "";
}
return "";
}
+/*
static char *choose_iftype_name(nfacct_rule_s *rule)
{
return strlen(rule->ifname) != 0 ? rule->ifname :
get_iftype_name(rule->iftype);
}
+*/
static stc_error_e exec_iptables_cmd(nfacct_rule_s *rule)
{
" traffic, for iftype %d, cmd %s, j %s",
rule->iftype, set_cmd, jump_cmd);
+ //LCOV_EXCL_START
/* for tethering */
if (rule->intend == NFACCT_WARN ||
rule->intend == NFACCT_BLOCK) {
ret_value_msg_if(ret != STC_ERROR_NONE, ret,
"can't del quota counter");
}
+ //LCOV_EXCL_STOP
}
if (rule->iotype & NFACCT_COUNTER_OUT) {
"engress traffic, for iftype %d, cmd %s, j %s",
rule->iftype, set_cmd, jump_cmd);
+ //LCOV_EXCL_START
/* for tethering */
if (rule->intend == NFACCT_WARN ||
rule->intend == NFACCT_BLOCK) {
ret_value_msg_if(ret != STC_ERROR_NONE, ret,
"can't del quota counter");
}
+ //LCOV_EXCL_STOP
}
return STC_ERROR_NONE;
}
int sock;
sock = socket(PF_NETLINK, SOCK_RAW, protocol);
if (sock < 0)
- return -EINVAL;
+ return -EINVAL; //LCOV_EXCL_LINE
struct sockaddr_nl src_addr = { 0, };
src_addr.nl_groups = groups;
if (bind(sock, (struct sockaddr *)&src_addr, sizeof(src_addr)) < 0) {
- close(sock);
- return -1;
+ close(sock); //LCOV_EXCL_LINE
+ return -1; //LCOV_EXCL_LINE
}
return sock;
};
ret = recvmsg(sock, &msg, 0);
if (ret == -1)
- return ret;
+ return ret; //LCOV_EXCL_LINE
if (msg.msg_flags & MSG_TRUNC) {
- errno = ENOSPC;
- return -1;
+ errno = ENOSPC; //LCOV_EXCL_LINE
+ return -1; //LCOV_EXCL_LINE
}
if (msg.msg_namelen != sizeof(struct sockaddr_nl)) {
- errno = EINVAL;
- return -1;
+ errno = EINVAL; //LCOV_EXCL_LINE
+ return -1; //LCOV_EXCL_LINE
}
return ret;
snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
fp = fopen(buf, "r");
if (fp == NULL)
- return STC_ERROR_FAIL;
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
if (fgets(cmdline_buf, PROC_NAME_MAX-1, fp) == NULL) {
- fclose(fp);
- return STC_ERROR_FAIL;
+ fclose(fp); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
fclose(fp);
return STC_ERROR_NONE;
}
+//LCOV_EXCL_START
pid_t find_pid_from_cmdline(char *cmdline)
{
pid_t pid = -1, foundpid = -1;
snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
return proc_get_data(path, buf, len);
}
+//LCOV_EXCL_STOP
int proc_get_status(pid_t pid, char status[][PROC_BUF_MAX])
{
char *saveptr = NULL;
if (fgets(status_buf, sizeof(status_buf), fp) == NULL) {
- fclose(fp);
- return STC_ERROR_FAIL;
+ fclose(fp); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
if (!updated[PROC_STATUS_NAME] && strstr(status_buf,
proc_value_s *lookup;
if (proc_tree == NULL) {
- STC_LOGE("tree is null");
- return NULL;
+ STC_LOGE("tree is null"); //LCOV_EXCL_LINE
+ return NULL; //LCOV_EXCL_LINE
}
lookup = g_tree_lookup(proc_tree, key);
return lookup;
}
+//LCOV_EXCL_START
static gboolean __proc_tree_foreach_print(gpointer key, gpointer value,
gpointer data)
{
return FALSE;
}
+//LCOV_EXCL_STOP
static void __proc_tree_printall(void)
{
- g_tree_foreach(proc_tree, __proc_tree_foreach_print, NULL);
+ g_tree_foreach(proc_tree, __proc_tree_foreach_print, NULL); //LCOV_EXCL_LINE
}
static proc_value_s * __proc_tree_find_parent(proc_value_s *value)
} while (lookup);
if (STC_DEBUG_LOG) {
- if (parent != NULL)
- STC_LOGD("\033[0;35mPARENT\033[0;m: tgid[\033[1;33m%s\033[0;m] pid[%s] "
+ if (parent != NULL) //LCOV_EXCL_LINE
+ STC_LOGD("\033[0;35mPARENT\033[0;m: tgid[\033[1;33m%s\033[0;m] pid[%s] " //LCOV_EXCL_LINE
"ppid[\033[1;35m%s\033[0;m] cmdline[\033[0;34m%s\033[0;m] name[%s]",
parent->status[PROC_STATUS_TGID], parent->status[PROC_STATUS_PID],
parent->status[PROC_STATUS_PPID], parent->cmdline,
proc_value_s *parent;
if (proc_tree == NULL) {
- STC_LOGE("tree is null");
- return;
+ STC_LOGE("tree is null"); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
lookup = g_tree_lookup(proc_tree, key);
if (lookup) {
if (STC_DEBUG_LOG)
- STC_LOGD("LOOKUP: tgid[\033[1;33m%s\033[0;m] pid[%s] ppid[\033[1;35m%s\033[0;m] "
+ STC_LOGD("LOOKUP: tgid[\033[1;33m%s\033[0;m] pid[%s] ppid[\033[1;35m%s\033[0;m] " //LCOV_EXCL_LINE
"cmdline[\033[0;34m%s\033[0;m] name[%s]", lookup->status[PROC_STATUS_TGID],
lookup->status[PROC_STATUS_PID], lookup->status[PROC_STATUS_PPID],
lookup->cmdline, lookup->status[PROC_STATUS_NAME]);
static void __proc_tree_remove(const proc_key_s *key)
{
if (proc_tree == NULL) {
- STC_LOGE("tree is null");
- return;
+ STC_LOGE("tree is null"); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
stc_manager_app_status_changed(STC_CMD_SET_TERMINATED, key->pid, NULL,
g_tree_remove(proc_tree, key);
if (STC_DEBUG_LOG)
- __proc_tree_printall();
+ __proc_tree_printall(); //LCOV_EXCL_LINE
}
static gboolean __check_excn(char *cmdline)
GIOChannel *gio = NULL;
if (nl_connector_sock != -1 &&
- nl_connector_gsource_id != 0) {
- STC_LOGE("Socket is already open");
- __STC_LOG_FUNC_EXIT__;
- return;
+ nl_connector_gsource_id != 0) { //LCOV_EXCL_LINE
+ STC_LOGE("Socket is already open"); //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
if (nl_connector_sock != -1) {
- close(nl_connector_sock);
- nl_connector_sock = -1;
+ close(nl_connector_sock); //LCOV_EXCL_LINE
+ nl_connector_sock = -1; //LCOV_EXCL_LINE
}
if (nl_connector_gsource_id != 0) {
- g_source_remove(nl_connector_gsource_id);
- nl_connector_gsource_id = 0;
+ g_source_remove(nl_connector_gsource_id); //LCOV_EXCL_LINE
+ nl_connector_gsource_id = 0; //LCOV_EXCL_LINE
}
nl_connector_sock = create_netlink(NETLINK_CONNECTOR, CN_IDX_PROC);
if (nl_connector_sock == -1) {
- __STC_LOG_FUNC_EXIT__;
- return;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
gio = g_io_channel_unix_new(nl_connector_sock);
static void __reopen_nl_connector_sock(void)
{
- __close_nl_connector_sock();
- __open_nl_connector_sock();
+ __close_nl_connector_sock(); //LCOV_EXCL_LINE
+ __open_nl_connector_sock(); //LCOV_EXCL_LINE
}
+//LCOV_EXCL_START
stc_error_e stc_manager_app_status_changed(stc_cmd_type_e cmd,
pid_t pid,
const gchar *app_id,
return ret;
}
+//LCOV_EXCL_STOP
static void __process_event_fork(int tgid, int pid)
{
if (__check_excn(cmdline)) {
if (STC_DEBUG_LOG)
- STC_LOGD("[%s] monitoring is excepted", cmdline);
+ STC_LOGD("[%s] monitoring is excepted", cmdline); //LCOV_EXCL_LINE
return;
}
key = MALLOC0(proc_key_s, 1);
if (key == NULL) {
- STC_LOGE("memory allocation failed");
- return;
+ STC_LOGE("memory allocation failed"); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
value = MALLOC0(proc_value_s, 1);
if (value == NULL) {
- STC_LOGE("memory allocation failed");
- FREE(key);
- return;
+ STC_LOGE("memory allocation failed"); //LCOV_EXCL_LINE
+ FREE(key); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
key->pid = tgid;
g_strlcpy(value->cmdline, cmdline, sizeof(value->cmdline));
if (STC_DEBUG_LOG) {
- STC_LOGD("\033[1;34mFORK\033[0;m: tgid[\033[1;33m%d\033[0;m] ppid=[\033[1;35m%s\033[0;m] "
+ STC_LOGD("\033[1;34mFORK\033[0;m: tgid[\033[1;33m%d\033[0;m] ppid=[\033[1;35m%s\033[0;m] " //LCOV_EXCL_LINE
"cmdline[\033[0;34m%s\033[0;m] pid[%d]", tgid, status[PROC_STATUS_PPID], cmdline, pid);
- STC_LOGD("STATUS: tgid[%s] pid[%s] ppid[%s] name[%s] state[%s] tracerpid[%s]",
+ STC_LOGD("STATUS: tgid[%s] pid[%s] ppid[%s] name[%s] state[%s] tracerpid[%s]", //LCOV_EXCL_LINE
status[PROC_STATUS_TGID], status[PROC_STATUS_PID], status[PROC_STATUS_PPID],
status[PROC_STATUS_NAME], status[PROC_STATUS_STATE], status[PROC_STATUS_TRACERPID]);
}
if (__check_excn(cmdline)) {
if (STC_DEBUG_LOG)
- STC_LOGD("[%s] monitoring is excepted", cmdline);
+ STC_LOGD("[%s] monitoring is excepted", cmdline); //LCOV_EXCL_LINE
return;
}
key = MALLOC0(proc_key_s, 1);
if (key == NULL) {
- STC_LOGE("memory allocation failed");
- return;
+ STC_LOGE("memory allocation failed"); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
value = MALLOC0(proc_value_s, 1);
if (value == NULL) {
- STC_LOGE("memory allocation failed");
- FREE(key);
- return;
+ STC_LOGE("memory allocation failed"); //LCOV_EXCL_LINE
+ FREE(key); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
key->pid = tgid;
g_strlcpy(value->cmdline, cmdline, sizeof(value->cmdline));
if (STC_DEBUG_LOG) {
- STC_LOGD("\033[1;32mEXEC\033[0;m: tgid[\033[1;33m%d\033[0;m] ppid=[\033[1;35m%s\033[0;m] "
+ STC_LOGD("\033[1;32mEXEC\033[0;m: tgid[\033[1;33m%d\033[0;m] ppid=[\033[1;35m%s\033[0;m] " //LCOV_EXCL_LINE
"cmdline[\033[0;34m%s\033[0;m] pid[%d]", tgid, status[PROC_STATUS_PPID], cmdline, pid);
- STC_LOGD("STATUS: tgid[%s] pid[%s] ppid[%s] name[%s] state[%s] tracerpid[%s]",
+ STC_LOGD("STATUS: tgid[%s] pid[%s] ppid[%s] name[%s] state[%s] tracerpid[%s]", //LCOV_EXCL_LINE
status[PROC_STATUS_TGID], status[PROC_STATUS_PID], status[PROC_STATUS_PPID],
status[PROC_STATUS_NAME], status[PROC_STATUS_STATE], status[PROC_STATUS_TRACERPID]);
}
return;
if (STC_DEBUG_LOG)
- STC_LOGD("\033[1;31mEXIT\033[0;m: tgid[\033[1;33m%d\033[0;m] "
+ STC_LOGD("\033[1;31mEXIT\033[0;m: tgid[\033[1;33m%d\033[0;m] " //LCOV_EXCL_LINE
"pid[%d] exitcode[\033[0;31m%d\033[0;m]", tgid, pid, exit_code);
__proc_tree_remove(&key);
(condition & G_IO_NVAL)) {
/* G_IO_ERR/G_IO_HUP/G_IO_NVAL received */
- STC_LOGE("Netlink Connector socket received G_IO event, closing"
+ STC_LOGE("Netlink Connector socket received G_IO event, closing" //LCOV_EXCL_LINE
" socket. G_IO_ERR [%d], G_IO_HUP [%d], G_IO_NVAL [%s]",
(condition & G_IO_ERR), (condition & G_IO_HUP),
(condition & G_IO_NVAL));
- __reopen_nl_connector_sock();
- __STC_LOG_FUNC_EXIT__;
- return FALSE;
+ __reopen_nl_connector_sock(); //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return FALSE; //LCOV_EXCL_LINE
}
memset(&msg, 0, sizeof(nl_connector_proc_event_s));
ret = read(sock, &msg, sizeof(nl_connector_proc_event_s));
if (ret == 0) {
- __STC_LOG_FUNC_EXIT__;
- return TRUE;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return TRUE; //LCOV_EXCL_LINE
}
switch (msg.proc_ev.what) {
int sock = nl_connector_sock;
if (sock == -1) {
- __STC_LOG_FUNC_EXIT__;
- return -1;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return -1; //LCOV_EXCL_LINE
}
memset(&msg, 0, sizeof(nl_connector_msg_s));
ret = send(sock, &msg, sizeof(nl_connector_msg_s), 0);
if (ret == -1) {
- STC_LOGE("Error sending netlink connector message");
- __STC_LOG_FUNC_EXIT__;
- return -1;
+ STC_LOGE("Error sending netlink connector message"); //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return -1; //LCOV_EXCL_LINE
}
__STC_LOG_FUNC_EXIT__;
int sock = nl_connector_sock;
if (sock == -1) {
- __STC_LOG_FUNC_EXIT__;
- return -1;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return -1; //LCOV_EXCL_LINE
}
memset(&msg, 0, sizeof(nl_connector_msg_s));
ret = send(sock, &msg, sizeof(nl_connector_msg_s), 0);
if (ret == -1) {
- STC_LOGE("Error sending netlink connector message");
- __STC_LOG_FUNC_EXIT__;
- return -1;
+ STC_LOGE("Error sending netlink connector message"); //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return -1; //LCOV_EXCL_LINE
}
__STC_LOG_FUNC_EXIT__;
__STC_LOG_FUNC_ENTER__;
if (nl_connector_sock == -1) {
- STC_LOGE("socket already closed");
- return;
+ STC_LOGE("socket already closed"); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
__unsubscribe_proc_events();
int current_sim = 0;
if (vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT_COUNT, &sim_slot_count) != 0) {
- STC_LOGD("failed to get sim slot count");
- return -1;
+ STC_LOGD("failed to get sim slot count"); //LCOV_EXCL_LINE
+ return -1; //LCOV_EXCL_LINE
}
if (sim_slot_count == SIM_SLOT_SINGLE) {
- STC_LOGD("It's single sim model");
- return current_sim;
+ STC_LOGD("It's single sim model"); //LCOV_EXCL_LINE
+ return current_sim; //LCOV_EXCL_LINE
}
if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, ¤t_sim) != 0) {
- STC_LOGD("failed to get default data service = %d\n",
+ STC_LOGD("failed to get default data service = %d\n", //LCOV_EXCL_LINE
current_sim);
- return -1;
+ return -1; //LCOV_EXCL_LINE
}
return current_sim;
TELEPHONY_GET_IMSI,
NULL);
if (message == NULL) {
- STC_LOGE("Failed to get services informations");
- goto done;
+ STC_LOGE("Failed to get services informations"); //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
DEBUG_PARAMS(message);
msin_len = strlen(msin);
if (msin_len + plmn_len >= IMSI_LENGTH) {
- STC_LOGD("Incorrect length of mobile subscriber identifier + net id");
- goto done;
+ STC_LOGD("Incorrect length of mobile subscriber identifier + net id"); //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
snprintf(imsi, IMSI_LENGTH, "%s%s", plmn, msin);
int current_sim = __telephony_get_current_sim();
if (current_sim < 0) {
- STC_LOGI("Sim not found");
- return;
+ STC_LOGI("Sim not found"); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
message = stc_manager_gdbus_call_sync(connection,
TELEPHONY_GET_MODEMS,
NULL);
if (message == NULL) {
- STC_LOGE("Failed to get services informations");
- return;
+ STC_LOGE("Failed to get services informations"); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
g_variant_get(message, "(as)", &iter);
FREE(modem_name);
break;
}
- current_sim--;
+ current_sim--; //LCOV_EXCL_LINE
}
__telephony_get_modem_subscriber_id(connection, default_modem_name);
if (profile == NULL)
return FALSE;
- return g_str_has_prefix(profile,
+ return g_str_has_prefix(profile, //LCOV_EXCL_LINE
CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX);
}
if (profile == NULL)
return FALSE;
- return g_str_has_prefix(profile, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX);
+ return g_str_has_prefix(profile, //LCOV_EXCL_LINE
+ CONNMAN_WIFI_SERVICE_PROFILE_PREFIX);
}
static gboolean __is_ethernet_profile(const char *profile)
if (profile == NULL)
return FALSE;
- return g_str_has_prefix(profile,
+ return g_str_has_prefix(profile, //LCOV_EXCL_LINE
CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX);
}
if (profile == NULL)
return FALSE;
- return g_str_has_prefix(profile,
+ return g_str_has_prefix(profile, //LCOV_EXCL_LINE
CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX);
}
CONNMAN_SERVICE_INTERFACE,
"GetProperties", NULL);
if (message == NULL) {
- STC_LOGE("Failed to get services informations");
- goto done;
+ STC_LOGE("Failed to get services informations"); //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
g_variant_get(message, "(a{sv})", &iter);
if (iter == NULL) {
- STC_LOGE("Profile %s doesn't exist", object_path);
- goto done;
+ STC_LOGE("Profile %s doesn't exist", object_path); //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
g_variant_get(variant, "a{sv}", &iter1);
if (iter1 == NULL)
- continue;
+ continue; //LCOV_EXCL_LINE
while (g_variant_iter_loop(iter1, "{sv}", &key1,
&variant1)) {
CONNMAN_MANAGER_INTERFACE,
"GetServices", NULL);
if (message == NULL) {
- STC_LOGE("Failed to get profiles");
- return STC_ERROR_FAIL;
+ STC_LOGE("Failed to get profiles"); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
g_variant_get(message, "(a(oa{sv}))", &iter);
while (g_variant_iter_loop(iter, "(oa{sv})", &object_path, &next)) {
if (object_path == NULL)
- continue;
+ continue; //LCOV_EXCL_LINE
if (__is_cellular_profile(object_path) &&
!__is_cellular_internet_profile(object_path))
g_variant_unref(message);
if (__is_cellular_profile(g_default_connection.path)) {
- g_default_connection.type = STC_IFACE_DATACALL;
- __telephony_update_default_modem_subscriber_id(connection);
+ g_default_connection.type = STC_IFACE_DATACALL; //LCOV_EXCL_LINE
+ __telephony_update_default_modem_subscriber_id(connection); //LCOV_EXCL_LINE
} else if (__is_wifi_profile(g_default_connection.path)) {
- g_default_connection.type = STC_IFACE_WIFI;
+ g_default_connection.type = STC_IFACE_WIFI; //LCOV_EXCL_LINE
} else if (__is_ethernet_profile(g_default_connection.path)) {
- g_default_connection.type = STC_IFACE_WIRED;
+ g_default_connection.type = STC_IFACE_WIRED; //LCOV_EXCL_LINE
} else if (__is_bluetooth_profile(g_default_connection.path)) {
- g_default_connection.type = STC_IFACE_BLUETOOTH;
+ g_default_connection.type = STC_IFACE_BLUETOOTH; //LCOV_EXCL_LINE
} else {
- g_default_connection.type = STC_IFACE_UNKNOWN;
+ g_default_connection.type = STC_IFACE_UNKNOWN; //LCOV_EXCL_LINE
}
__get_default_connection_info(connection, g_default_connection.path);
}
} else {
if (g_strcmp0(g_default_connection.path, path) == 0) {
- __reset_default_connection_data();
- __get_default_profile(stc->connection);
+ __reset_default_connection_data(); //LCOV_EXCL_LINE
+ __get_default_profile(stc->connection); //LCOV_EXCL_LINE
}
}
} else if (g_strcmp0(sigvalue, "Roaming") == 0) {
+ //LCOV_EXCL_START
if (g_strcmp0(g_default_connection.path, path) == 0) {
gboolean roaming = 0;
g_default_connection.roaming = roaming;
}
}
+ //LCOV_EXCL_STOP
} else {
;//Do nothing
}
ret = system_info_get_platform_string("tizen.org/system/model_name", &model);
if (ret != SYSTEM_INFO_ERROR_NONE) {
- STC_LOGE("Failed to get system information(%d)", ret);
- return FALSE;
+ STC_LOGE("Failed to get system information(%d)", ret); //LCOV_EXCL_LINE
+ return FALSE; //LCOV_EXCL_LINE
}
if (model && strncmp(model, "Emulator", strlen("Emulator")) == 0) {
- g_free(model);
- return TRUE;
+ g_free(model); //LCOV_EXCL_LINE
+ return TRUE; //LCOV_EXCL_LINE
}
- g_free(model);
- return FALSE;
+ g_free(model); //LCOV_EXCL_LINE
+ return FALSE; //LCOV_EXCL_LINE
}
gboolean stc_emulator_is_emulated(void)
if (process_name != NULL)
data.process_name = process_name;
else
- data.process_name = "none";
+ data.process_name = "none"; //LCOV_EXCL_LINE
exe_type = strtok_r(NULL, "\n", &save_ptr);
if (exe_type != NULL)
data.exe_type = exe_type;
else
- data.exe_type = "none";
+ data.exe_type = "none"; //LCOV_EXCL_LINE
if (exception_cb(&data, user_data) == STC_CANCEL)
break;
if (ret == PMINFO_R_OK) {
if (g_hash_table_insert(g_pkginfo_filter_hash,
g_strdup(pkgname), g_strdup(EXE_TYPE_APPLICATION)) != TRUE)
- STC_LOGE("Failed to insert hash table");
+ STC_LOGE("Failed to insert hash table"); //LCOV_EXCL_LINE
}
return STC_CONTINUE;
data.exe_type = EXE_TYPE_APPLICATION;
if (excn_cb(&data, NULL) == STC_CANCEL)
- STC_LOGE("Failed to insert hash table");
+ STC_LOGE("Failed to insert hash table"); //LCOV_EXCL_LINE
}
return STC_CONTINUE;
PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE,
INTERNET_PRIVILEGE);
if (ret != PMINFO_R_OK) {
- STC_LOGE("Failed to add pkginfo filter string");
- err = STC_ERROR_FAIL;
- goto out;
+ STC_LOGE("Failed to add pkginfo filter string"); //LCOV_EXCL_LINE
+ err = STC_ERROR_FAIL; //LCOV_EXCL_LINE
+ goto out; //LCOV_EXCL_LINE
}
ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle,
__pkginfo_filter_list_cb, NULL);
if (ret != PMINFO_R_OK) {
- STC_LOGE("Failed to foreach pkginfo filter");
- err = STC_ERROR_FAIL;
- goto out;
+ STC_LOGE("Failed to foreach pkginfo filter"); //LCOV_EXCL_LINE
+ err = STC_ERROR_FAIL; //LCOV_EXCL_LINE
+ goto out; //LCOV_EXCL_LINE
}
ret = pkgmgrinfo_pkginfo_get_list(__pkginfo_pkg_list_cb, exception_cb);
if (ret != PMINFO_R_OK) {
- STC_LOGE("Failed to get pkginfo list");
- err = STC_ERROR_FAIL;
- goto out;
+ STC_LOGE("Failed to get pkginfo list"); //LCOV_EXCL_LINE
+ err = STC_ERROR_FAIL; //LCOV_EXCL_LINE
+ goto out; //LCOV_EXCL_LINE
}
out:
FREE(key);
}
+//LCOV_EXCL_START
static gboolean __processes_tree_foreach_print(gpointer key, gpointer value,
gpointer data)
{
{
g_tree_foreach(g_system->apps, __apps_tree_foreach_print, NULL);
}
+//LCOV_EXCL_STOP
static gboolean __apps_tree_foreach_remove_pid(gpointer key, gpointer value,
gpointer data)
if (!g_tree_remove(app_value->processes, context->proc_key)) {
if (STC_DEBUG_LOG)
- STC_LOGD("key not found");
+ STC_LOGD("key not found"); //LCOV_EXCL_LINE
return FALSE;
}
return lookup;
}
+//LCOV_EXCL_START
static gboolean __processes_tree_check_empty(gpointer key, gpointer value,
gpointer data)
{
(*pid_count)++;
return TRUE;
}
+//LCOV_EXCL_STOP
static gboolean __add_application_monitor(gpointer key, gpointer value,
gpointer data)
struct nfacct_rule counter;
if (!stc->carg) {
- stc->carg = MALLOC0(counter_arg_s, 1);
- if (stc->carg == NULL)
- return FALSE;
+ stc->carg = MALLOC0(counter_arg_s, 1); //LCOV_EXCL_LINE
+ if (stc->carg == NULL) //LCOV_EXCL_LINE
+ return FALSE; //LCOV_EXCL_LINE
- stc->carg->sock = stc_monitor_get_counter_socket();
+ stc->carg->sock = stc_monitor_get_counter_socket(); //LCOV_EXCL_LINE
}
memset(&counter, 0, sizeof(struct nfacct_rule));
struct nfacct_rule counter;
if (!stc->carg) {
- stc->carg = MALLOC0(counter_arg_s, 1);
- if (stc->carg == NULL)
- return FALSE;
+ stc->carg = MALLOC0(counter_arg_s, 1); //LCOV_EXCL_LINE
+ if (stc->carg == NULL) //LCOV_EXCL_LINE
+ return FALSE; //LCOV_EXCL_LINE
- stc->carg->sock = stc_monitor_get_counter_socket();
+ stc->carg->sock = stc_monitor_get_counter_socket(); //LCOV_EXCL_LINE
}
memset(&counter, 0, sizeof(struct nfacct_rule));
effective_data_warn_limit -= info.data_counter;
if (effective_data_limit < 0) {
- effective_data_limit = 0;
- rstn_value->data_limit_reached = TRUE;
+ effective_data_limit = 0; //LCOV_EXCL_LINE
+ rstn_value->data_limit_reached = TRUE; //LCOV_EXCL_LINE
}
if (effective_data_warn_limit < 0)
- effective_data_warn_limit = 0;
+ effective_data_warn_limit = 0; //LCOV_EXCL_LINE
STC_LOGD("datausage [%lld] bytes", info.data_counter);
}
struct nfacct_rule counter;
stc_s *stc = stc_get_manager();
if (!stc) {
- g_free(default_ifname);
- return;
+ g_free(default_ifname); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
if (!stc->carg) {
- stc->carg = MALLOC0(counter_arg_s, 1);
- if (stc->carg == NULL) {
- g_free(default_ifname);
- return;
+ stc->carg = MALLOC0(counter_arg_s, 1); //LCOV_EXCL_LINE
+ if (stc->carg == NULL) { //LCOV_EXCL_LINE
+ g_free(default_ifname); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
- stc->carg->sock =
- stc_monitor_get_counter_socket();
+ stc->carg->sock = stc_monitor_get_counter_socket(); //LCOV_EXCL_LINE
}
counter.carg = stc->carg;
struct nfacct_rule counter;
stc_s *stc = stc_get_manager();
if (!stc) {
- g_free(default_ifname);
- return;
+ g_free(default_ifname); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
if (!stc->carg) {
- stc->carg = MALLOC0(counter_arg_s, 1);
- if (stc->carg == NULL) {
- g_free(default_ifname);
- return;
+ stc->carg = MALLOC0(counter_arg_s, 1); //LCOV_EXCL_LINE
+ if (stc->carg == NULL) { //LCOV_EXCL_LINE
+ g_free(default_ifname); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
- stc->carg->sock =
- stc_monitor_get_counter_socket();
+ stc->carg->sock = stc_monitor_get_counter_socket(); //LCOV_EXCL_LINE
}
counter.carg = stc->carg;
}
}
+//LCOV_EXCL_START
static gboolean __remove_rstns_foreach_application(gpointer key,
gpointer value,
gpointer data)
out:
return FALSE;
}
+//LCOV_EXCL_STOP
static void __remove_rstns_for_application(gchar *app_id)
{
lookup = __application_lookup(g_system->apps, app_key);
if (!lookup) {
- STC_LOGE("app_key not found");
- return STC_ERROR_NO_DATA;
+ STC_LOGE("app_key not found"); //LCOV_EXCL_LINE
+ return STC_ERROR_NO_DATA; //LCOV_EXCL_LINE
}
g_tree_foreach(lookup->processes, __processes_tree_check_empty,
}
if (!g_tree_remove(g_system->apps, app_key)) {
- ret = STC_ERROR_NO_DATA;
- STC_LOGE("key not found");
+ ret = STC_ERROR_NO_DATA; //LCOV_EXCL_LINE
+ STC_LOGE("key not found"); //LCOV_EXCL_LINE
}
return ret;
GIOCondition condition,
gpointer user_data);
+//LCOV_EXCL_START
static stc_error_e __close_and_reopen_contr_sock(stc_system_s *system)
{
GIOChannel *gio = NULL;
goto try_next_callback;
if (rstn_value->data_limit_reached == TRUE) {
- context->data_limit_reached = TRUE;
- goto try_next_callback;
+ context->data_limit_reached = TRUE; //LCOV_EXCL_LINE
+ goto try_next_callback; //LCOV_EXCL_LINE
}
classid = context->counter->classid;
try_next_callback:
return rv;
}
+//LCOV_EXCL_STOP
static gboolean __update_app_statistics(gpointer key, gpointer value,
gpointer data)
if (STC_IFACE_DATACALL == stat_key.iftype)
stat_key.subscriber_id = g_strdup(default_connection->subscriber_id);
else
- stat_key.subscriber_id = g_strdup("none_subid");
+ stat_key.subscriber_id = g_strdup("none_subid"); //LCOV_EXCL_LINE
g_strlcpy(stat_key.ifname, default_connection->ifname,
MAX_IFACE_LENGTH);
return G_SOURCE_REMOVE;
}
+//LCOV_EXCL_START
static gboolean __update_counter_statistics(gpointer key, gpointer value,
gpointer data)
{
STC_LOGI("Flushed rstns counters to database");
return G_SOURCE_REMOVE;
}
+//LCOV_EXCL_STOP
static void __app_counter_update(stc_app_key_s *app_key,
stc_app_value_s *app_value,
g_system->apps_tree_updated = TRUE;
if (STC_DEBUG_LOG)
- __apps_tree_foreach_print(app_key, app_value, NULL);
+ __apps_tree_foreach_print(app_key, app_value, NULL); //LCOV_EXCL_LINE
break;
case NFACCT_COUNTER_OUT:
app_value->data_usage.out_bytes += context->bytes;
g_system->apps_tree_updated = TRUE;
if (STC_DEBUG_LOG)
- __apps_tree_foreach_print(app_key, app_value, NULL);
+ __apps_tree_foreach_print(app_key, app_value, NULL); //LCOV_EXCL_LINE
break;
default:
- STC_LOGE("unknown iotype");
+ STC_LOGE("unknown iotype"); //LCOV_EXCL_LINE
}
}
};
if (STC_DEBUG_LOG)
- STC_LOGD("cnt_name %s", cnt_name);
+ STC_LOGD("cnt_name %s", cnt_name); //LCOV_EXCL_LINE
if (!recreate_counter_by_name(cnt_name, &counter)) {
- STC_LOGE("Can't parse counter name %s", cnt_name);
- return;
+ STC_LOGE("Can't parse counter name %s", cnt_name); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
STC_LOGI("classid %lu, iftype %u, iotype %d, intend %d, ifname %s, bytes %lld",
netlink_serialization_command *netlink =
netlink_create_command(&ser_params);
if (!netlink) {
- STC_LOGE("Can not create command");
- return;
+ STC_LOGE("Can not create command"); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
netlink->deserialize_answer(&(netlink->params));
int ret;
stc_s *stc = stc_get_manager();
+#ifdef TIZEN_GTESTS
+ void __gcov_flush(void);
+ __gcov_flush();
+#endif
+
if ((condition & G_IO_ERR) || (condition & G_IO_HUP) ||
(condition & G_IO_NVAL)) {
/* G_IO_ERR/G_IO_HUP/G_IO_NVAL received */
- STC_LOGE("Counter socket received G_IO event, closing socket."
+ STC_LOGE("Counter socket received G_IO event, closing socket." //LCOV_EXCL_LINE
"G_IO_ERR [%d], G_IO_HUP [%d], G_IO_NVAL [%s]",
(condition & G_IO_ERR), (condition & G_IO_HUP),
(condition & G_IO_NVAL));
- __close_and_reopen_contr_sock(g_system);
- return FALSE;
+ __close_and_reopen_contr_sock(g_system); //LCOV_EXCL_LINE
+ return FALSE; //LCOV_EXCL_LINE
}
ans = MALLOC0(struct genl, 1);
if (ans == NULL) {
- STC_LOGE("Failed allocate memory to genl reply message");
- return TRUE;
+ STC_LOGE("Failed allocate memory to genl reply message"); //LCOV_EXCL_LINE
+ return TRUE; //LCOV_EXCL_LINE
}
if (stc == NULL) {
- STC_LOGE("Can't get stc data");
- goto out;
+ STC_LOGE("Can't get stc data"); //LCOV_EXCL_LINE
+ goto out; //LCOV_EXCL_LINE
}
ret = read_netlink(sock, ans, sizeof(struct genl));
g_idle_add(__flush_apps_stats_to_database, NULL);
g_idle_add(__flush_rstns_counter_to_database, NULL);
out:
+
FREE(ans);
return TRUE;
}
stc->carg->sock = stc_monitor_get_counter_socket();
}
+#ifdef TIZEN_GTESTS
+ void __gcov_flush(void);
+ __gcov_flush();
+#endif
+
/* STC_LOGD("Get all counters"); */
nfacct_send_get_all(stc->carg);
return FALSE;
}
+//LCOV_EXCL_START
static gboolean __add_restriction(gpointer key, gpointer value, gpointer data)
{
stc_rstn_key_s *rstn_key = (stc_rstn_key_s *)key;
return FALSE;
}
+//LCOV_EXCL_STOP
static stc_error_e __rstn_tree_remove(stc_rstn_key_s *key)
{
lookup_value = __rstn_lookup(g_system->rstns, key);
if (!lookup_value) {
- STC_LOGE("key not found");
- return STC_ERROR_NO_DATA;
+ STC_LOGE("key not found"); //LCOV_EXCL_LINE
+ return STC_ERROR_NO_DATA; //LCOV_EXCL_LINE
}
__remove_restriction(key, lookup_value, NULL);
table_counters_delete(lookup_value->restriction_id);
if (!g_tree_remove(g_system->rstns, key)) {
- STC_LOGD("key not found");
- return STC_ERROR_NO_DATA;
+ STC_LOGD("key not found"); //LCOV_EXCL_LINE
+ return STC_ERROR_NO_DATA; //LCOV_EXCL_LINE
}
return STC_ERROR_NONE;
if (!rstn_value) {
stc_rstn_key_s *rstn_key = MALLOC0(stc_rstn_key_s, 1);
if (!rstn_key) {
- STC_LOGE("rstn_key allocation failed");
- return STC_ERROR_OUT_OF_MEMORY;
+ STC_LOGE("rstn_key allocation failed"); //LCOV_EXCL_LINE
+ return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
}
rstn_value = MALLOC0(stc_rstn_value_s, 1);
if (!rstn_value) {
- STC_LOGE("rstn_value allocation failed");
- FREE(rstn_key);
- return STC_ERROR_OUT_OF_MEMORY;
+ STC_LOGE("rstn_value allocation failed"); //LCOV_EXCL_LINE
+ FREE(rstn_key); //LCOV_EXCL_LINE
+ return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
}
rstn_key->app_id = g_strdup(key->app_id);
return STC_ERROR_NONE;
}
+//LCOV_EXCL_START
static stc_cb_ret_e __insert_restriction_cb(const table_restrictions_info *info,
void *user_data)
{
out:
return FALSE;
}
+//LCOV_EXCL_STOP
static void __add_rstns_for_application(gchar *app_id)
{
stc_app_value_s app_value;
if (app_id == NULL)
- return;
+ return; //LCOV_EXCL_LINE
memset(&app_key, 0, sizeof(stc_app_key_s));
memset(&app_value, 0, sizeof(stc_app_value_s));
ret = vconf_get_int(key, value);
if (ret != VCONF_OK) {
- STC_LOGE("Failed to get vconfkey [%s] value", key);
- return -1;
+ STC_LOGE("Failed to get vconfkey [%s] value", key); //LCOV_EXCL_LINE
+ return -1; //LCOV_EXCL_LINE
}
return 0;
}
+//LCOV_EXCL_START
static int __vconf_set_int(const char *key, int value)
{
int ret = 0;
ret = vconf_set_int(key, value);
if (ret != VCONF_OK) {
- STC_LOGE("Failed to set vconfkey [%s] value", key);
- return -1;
+ STC_LOGE("Failed to set vconfkey [%s] value", key); //LCOV_EXCL_LINE
+ return -1; //LCOV_EXCL_LINE
}
return 0;
return STC_ERROR_NONE;
}
+//LCOV_EXCL_STOP
#if 0
static void __excn_hash_foreach_print(gpointer key, gpointer value,
}
#endif
+//LCOV_EXCL_START
static gboolean __remove_exception_app(gpointer key, gpointer value,
gpointer data)
{
return FALSE;
}
+//LCOV_EXCL_STOP
static void __remove_exception_appall(void)
{
- g_hash_table_foreach_remove(g_system->excns_hash,
+ g_hash_table_foreach_remove(g_system->excns_hash, //LCOV_EXCL_LINE
__remove_exception_app, NULL);
}
if (g_hash_table_insert(g_system->excns_hash,
g_strdup(info->process_name),
g_strdup(info->exe_type)) != TRUE)
- ret = STC_CANCEL;
+ ret = STC_CANCEL; //LCOV_EXCL_LINE
return ret;
}
/* __excn_hash_printall(); */
}
+//LCOV_EXCL_START
static gboolean __update_exceptions_app_list(void *user_data)
{
__remove_exception_appall();
return TRUE;
}
+//LCOV_EXCL_STOP
stc_error_e stc_monitor_init(void)
{
/* create netlink socket for updating kernel counters */
system->contr_sock = create_netlink(NETLINK_NETFILTER, 0);
if (system->contr_sock < 0) {
- STC_LOGE("failed to open socket");
- FREE(system);
- return STC_ERROR_FAIL;
+ STC_LOGE("failed to open socket"); //LCOV_EXCL_LINE
+ FREE(system); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
gio = g_io_channel_unix_new(system->contr_sock);
__update_contr_cb,
NULL);
if (g_system->contr_timer_id == 0) {
- STC_LOGE("Failed to register kernel counters update timer");
- __close_contr_sock(g_system);
- return STC_ERROR_FAIL;
+ STC_LOGE("Failed to register kernel counters update timer"); //LCOV_EXCL_LINE
+ __close_contr_sock(g_system); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
__vconf_get_int(VCONFKEY_STC_BACKGROUND_STATE,
lookup = __application_lookup(g_system->apps, &app_key);
if (lookup) {
- STC_LOGD("app_key already present");
- return STC_ERROR_NONE;
+ STC_LOGD("app_key already present"); //LCOV_EXCL_LINE
+ return STC_ERROR_NONE; //LCOV_EXCL_LINE
}
key = MALLOC0(stc_app_key_s, 1);
if (!key) {
- STC_LOGE("key allocation failed");
- return STC_ERROR_OUT_OF_MEMORY;
+ STC_LOGE("key allocation failed"); //LCOV_EXCL_LINE
+ return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
}
value = MALLOC0(stc_app_value_s, 1);
if (!value) {
- STC_LOGE("value allocation failed");
- FREE(key);
- return STC_ERROR_OUT_OF_MEMORY;
+ STC_LOGE("value allocation failed"); //LCOV_EXCL_LINE
+ FREE(key); //LCOV_EXCL_LINE
+ return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
}
key->app_id = g_strdup(app_key.app_id);
app_lookup = __application_lookup(g_system->apps, &app_key);
if (!app_lookup) {
- STC_LOGD("app_key not found");
- return STC_ERROR_FAIL;
+ STC_LOGD("app_key not found"); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
proc_lookup = __process_lookup(app_lookup->processes, &proc_key);
if (proc_lookup) {
- STC_LOGD("proc_key already present");
- return STC_ERROR_NONE;
+ STC_LOGD("proc_key already present"); //LCOV_EXCL_LINE
+ return STC_ERROR_NONE; //LCOV_EXCL_LINE
}
key = MALLOC0(stc_process_key_s, 1);
if (!key) {
- STC_LOGE("key allocation failed");
- return STC_ERROR_OUT_OF_MEMORY;
+ STC_LOGE("key allocation failed"); //LCOV_EXCL_LINE
+ return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
}
value = MALLOC0(stc_process_value_s, 1);
if (!value) {
- STC_LOGE("value allocation failed");
- FREE(key);
- return STC_ERROR_OUT_OF_MEMORY;
+ STC_LOGE("value allocation failed"); //LCOV_EXCL_LINE
+ FREE(key); //LCOV_EXCL_LINE
+ return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
}
key->pid = proc_key.pid;
place_pids_to_net_cgroup(proc_key.pid, app_key.app_id);
if (STC_DEBUG_LOG)
- __apps_tree_printall();
+ __apps_tree_printall(); //LCOV_EXCL_LINE
return ret;
}
__application_remove_if_empty(context.app_key);
if (STC_DEBUG_LOG)
- __apps_tree_printall();
+ __apps_tree_printall(); //LCOV_EXCL_LINE
return ret;
}
+//LCOV_EXCL_START
stc_error_e stc_monitor_process_update_ground(const stc_app_key_s app_key,
const stc_process_key_s proc_key,
stc_app_state_e ground)
return ret;
}
+//LCOV_EXCL_STOP
void stc_monitor_update_rstn_by_default_connection(void *data)
{
default_connection_s *new_connection = (default_connection_s *)data;
if (old_connection.path != NULL) {
+ //LCOV_EXCL_START
if (g_system->apps)
g_tree_foreach(g_system->apps,
__remove_application_monitor,
(gpointer)&old_connection);
iptables_flush_chains();
+ //LCOV_EXCL_STOP
}
FREE(old_connection.path);
value.classid = STC_UNKNOWN_CLASSID;
if (value.classid == STC_BACKGROUND_APP_CLASSID) {
- __set_background_state(TRUE);
- __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, g_system->background_state);
- __process_update_background();
+ __set_background_state(TRUE); //LCOV_EXCL_LINE
+ __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, g_system->background_state); //LCOV_EXCL_LINE
+ __process_update_background(); //LCOV_EXCL_LINE
}
value.data_limit = info->data_limit;
};
if (!strcmp(key.app_id, STC_BACKGROUND_APP_ID)) {
- __set_background_state(FALSE);
- __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, g_system->background_state);
- __process_update_background();
+ __set_background_state(FALSE); //LCOV_EXCL_LINE
+ __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, g_system->background_state); //LCOV_EXCL_LINE
+ __process_update_background(); //LCOV_EXCL_LINE
}
ret = __rstn_tree_remove(&key);
*/
#include "stc-manager-gdbus.h"
+#include "stc-manager.h"
#include "stc-statistics.h"
#include "stc-restriction.h"
#include "stc-default-connection.h"
return ret;
}
+static gboolean __stc_manager_gdbus_manager_init(stc_s *stc)
+{
+ __STC_LOG_FUNC_ENTER__;
+ gboolean ret = TRUE;
+ gchar *s = NULL;
+
+ StcObjectSkeleton *object = NULL;
+ StcManager *manager = NULL;
+ s = g_strdup_printf(STC_DBUS_SERVICE_MANAGER_PATH);
+
+ object = stc_object_skeleton_new(s);
+ g_free(s);
+
+ manager = stc_manager_skeleton_new();
+ stc_object_skeleton_set_manager(object, manager);
+ g_object_unref(manager);
+
+ g_signal_connect(manager, "handle-stop",
+ G_CALLBACK(handle_manager_stop), stc);
+
+ g_dbus_object_manager_server_export(stc->obj_mgr,
+ G_DBUS_OBJECT_SKELETON(object));
+ g_object_unref(object);
+
+ stc->manager_obj = (gpointer)manager;
+
+ __STC_LOG_FUNC_EXIT__;
+ return ret;
+}
+
+
static void __stc_manager_gdbus_on_bus_acquired(GDBusConnection *connection,
const gchar *name,
gpointer user_data)
stc->connection = connection;
if (__stc_manager_gdbus_statistics_init(stc) == FALSE) {
- STC_LOGE("Can not signal connect to statistics");
+ STC_LOGE("Can not signal connect to statistics"); //LCOV_EXCL_LINE
/* Deinitialize and quit manager */
}
if (__stc_manager_gdbus_restriction_init(stc) == FALSE) {
- STC_LOGE("Cannot signal connect to restriction");
+ STC_LOGE("Cannot signal connect to restriction"); //LCOV_EXCL_LINE
+ /* Deinitialize and quit manager */
+ }
+
+ if (__stc_manager_gdbus_manager_init(stc) == FALSE) {
+ STC_LOGE("Cannot signal connect to manager"); //LCOV_EXCL_LINE
/* Deinitialize and quit manager */
}
STC_LOGD("name : %s", name);
}
+//LCOV_EXCL_START
static void __stc_manager_gdbus_on_name_lost(GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
STC_LOGD("name : %s", name);
}
+//LCOV_EXCL_STOP
void stc_manager_gdbus_init(gpointer stc_data)
{
stc->statistics_obj = NULL;
stc->restriction_obj = NULL;
+ stc->manager_obj = NULL;
__STC_LOG_FUNC_EXIT__;
}
GVariant *reply = NULL;
if (connection == NULL) {
- STC_LOGE("Failed to get GDBusconnection");
- return reply;
+ STC_LOGE("Failed to get GDBusconnection"); //LCOV_EXCL_LINE
+ return reply; //LCOV_EXCL_LINE
}
reply = g_dbus_connection_call_sync(connection,
if (reply == NULL) {
if (error != NULL) {
- STC_LOGE("g_dbus_connection_call_sync() failed"
+ STC_LOGE("g_dbus_connection_call_sync() failed" //LCOV_EXCL_LINE
"error [%d: %s]", error->code, error->message);
- g_error_free(error);
+ g_error_free(error); //LCOV_EXCL_LINE
} else {
- STC_LOGE("g_dbus_connection_call_sync() failed");
+ STC_LOGE("g_dbus_connection_call_sync() failed"); //LCOV_EXCL_LINE
}
return NULL;
GDestroyNotify user_data_free_func)
{
if (connection == NULL) {
- STC_LOGE("Failed to get GDBusconnection");
- return 0;
+ STC_LOGE("Failed to get GDBusconnection"); //LCOV_EXCL_LINE
+ return 0; //LCOV_EXCL_LINE
}
return g_dbus_connection_signal_subscribe(connection,
guint subscription_id)
{
if (connection == NULL) {
- STC_LOGE("Failed to get GDBusconnection");
- return;
+ STC_LOGE("Failed to get GDBusconnection"); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
g_dbus_connection_signal_unsubscribe(connection, subscription_id);
GVariant *value = NULL;
if (!cb) {
- __STC_LOG_FUNC_EXIT__;
- return;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
GError *error = NULL;
if (connection == NULL) {
- STC_LOGE("GDBusconnection is NULL");
+ STC_LOGE("GDBusconnection is NULL"); //LCOV_EXCL_LINE
return 0;
}
parameters,
&error);
if (rv != TRUE) {
- STC_LOGE("Failed to emit signal [%s] interface [%s] Error [%s]",
+ STC_LOGE("Failed to emit signal [%s] interface [%s] Error [%s]", //LCOV_EXCL_LINE
signal_name, interface_name, error->message);
- g_error_free(error);
+ g_error_free(error); //LCOV_EXCL_LINE
} else {
STC_LOGD("[%s] signal sent on [%s] interface", signal_name,
interface_name);
return rv;
}
+
+gboolean handle_manager_stop(StcManager *object,
+ GDBusMethodInvocation *invocation)
+{
+ __STC_LOG_FUNC_ENTER__;
+ GVariant *return_parameters = NULL;
+
+ STC_LOGI("stc manager stop");
+
+ return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
+
+ DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
+ STC_DBUS_REPLY(invocation, return_parameters);
+
+ stc_stop_manager();
+
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
+}
static void *handle_plugin;
static stc_plugin_s *stc_plugin;
+//LCOV_EXCL_START
void stc_manager_plugin_init(void)
{
__STC_LOG_FUNC_ENTER__;
__STC_LOG_FUNC_EXIT__;
return stc_plugin->deregister_state_changed_cb(stc);
}
+//LCOV_EXCL_STOP
keyfile = g_key_file_new();
if (!g_key_file_load_from_file(keyfile, path, 0, &error)) {
- STC_LOGD("Unable to load [%s] : %s", path, error->message);
- g_clear_error(&error);
- g_key_file_free(keyfile);
- keyfile = NULL;
+ STC_LOGD("Unable to load [%s] : %s", path, error->message); //LCOV_EXCL_LINE
+ g_clear_error(&error); //LCOV_EXCL_LINE
+ g_key_file_free(keyfile); //LCOV_EXCL_LINE
+ keyfile = NULL; //LCOV_EXCL_LINE
}
return keyfile;
data = g_key_file_to_data(keyfile, &length, NULL);
if (!g_file_set_contents(path, data, length, &error)) {
- STC_LOGD("Failed to save information : %s", error->message);
- g_error_free(error);
- ret = -EIO;
+ STC_LOGD("Failed to save information : %s", error->message); //LCOV_EXCL_LINE
+ g_error_free(error); //LCOV_EXCL_LINE
+ ret = -EIO; //LCOV_EXCL_LINE
}
__sync_file_to_disk(path);
return ret;
}
+//LCOV_EXCL_START
gboolean stc_util_get_config_bool(char *key)
{
char path[MAX_PATH_LENGTH];
return value;
}
+//LCOV_EXCL_STOP
int stc_util_get_config_int(char *key)
{
keyfile = __load_key_file(path);
if (!keyfile)
- keyfile = g_key_file_new();
+ keyfile = g_key_file_new(); //LCOV_EXCL_LINE
value = g_key_file_get_integer(keyfile, path, key, NULL);
return value;
}
+//LCOV_EXCL_START
API void stc_util_set_debuglog(int debuglog)
{
g_debuglog = debuglog;
}
+//LCOV_EXCL_STOP
API int stc_util_get_debuglog(void)
{
keyfile = __load_key_file(path);
if (!keyfile)
- keyfile = g_key_file_new();
+ keyfile = g_key_file_new(); //LCOV_EXCL_LINE
g_key_file_set_integer(keyfile, path, INFO_DEBUGLOG, 0);
stc_deinit_db_guard();
stc_db_deinitialize();
+ iptables_flush_chains();
iptables_deinit();
stc_manager_gdbus_deinit((gpointer)g_stc);
stc_app_lifecycle_monitor_deinit();
stc = MALLOC0(stc_s, 1);
if (!stc) {
- STC_LOGE("Failed to allocate memory for manager structure");
- return NULL;
+ STC_LOGE("Failed to allocate memory for manager structure"); //LCOV_EXCL_LINE
+ return NULL; //LCOV_EXCL_LINE
}
g_stc = stc;
return stc;
handle_error:
- STC_LOGD("Failed to initialize stc manager");
- __stc_manager_deinit();
- return NULL;
+ STC_LOGD("Failed to initialize stc manager"); //LCOV_EXCL_LINE
+ __stc_manager_deinit(); //LCOV_EXCL_LINE
+ return NULL; //LCOV_EXCL_LINE
}
stc_s *stc_get_manager(void)
return g_stc;
}
+void stc_stop_manager(void)
+{
+ if (g_stc && g_stc->main_loop)
+ g_main_loop_quit(g_stc->main_loop);
+}
+
gint32 main(gint32 argc, gchar *argv[])
{
GMainLoop *main_loop = NULL;
STC_LOGI("Smart Traffic Control Manager");
+#ifdef TIZEN_GTESTS
+ setenv("GCOV_PREFIX", "/tmp/daemon", 1);
+#endif
+
if (daemon(0, 0) != 0)
- STC_LOGE("Can't start daemon");
+ STC_LOGE("Can't start daemon"); //LCOV_EXCL_LINE
/* Initialize required subsystems */
#if !GLIB_CHECK_VERSION(2, 35, 0)
__STC_LOG_FUNC_ENTER__;
if (rule == NULL) {
- __STC_LOG_FUNC_EXIT__;
- return FALSE;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return FALSE; //LCOV_EXCL_LINE
}
if (rst_type <= RST_UNDEFINDED || rst_type >= RST_MAX_VALUE) {
- __STC_LOG_FUNC_EXIT__;
- return FALSE;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return FALSE; //LCOV_EXCL_LINE
}
if (rule->iftype <= STC_IFACE_UNKNOWN ||
rule->iftype >= STC_IFACE_LAST_ELEM) {
- __STC_LOG_FUNC_EXIT__;
- return FALSE;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return FALSE; //LCOV_EXCL_LINE
}
if (rule->roaming >= STC_ROAMING_LAST_ELEM) {
- __STC_LOG_FUNC_EXIT__;
- return FALSE;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return FALSE; //LCOV_EXCL_LINE
}
if (rule->subscriber_id == NULL) {
- __STC_LOG_FUNC_EXIT__;
- return FALSE;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return FALSE; //LCOV_EXCL_LINE
}
if (rule->app_id == NULL) {
- __STC_LOG_FUNC_EXIT__;
- return FALSE;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return FALSE; //LCOV_EXCL_LINE
}
__STC_LOG_FUNC_EXIT__;
__STC_LOG_FUNC_ENTER__;
if (!builder || !info) {
- __STC_LOG_FUNC_EXIT__;
- return;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
g_variant_builder_add(builder, "{sv}", "app_id",
GVariantBuilder sub_builder;
if (!info || !builder) {
- __STC_LOG_FUNC_EXIT__;
- return STC_CANCEL;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_CANCEL; //LCOV_EXCL_LINE
}
g_variant_builder_init(&sub_builder, G_VARIANT_TYPE("a{sv}"));
GVariantBuilder *builder = (GVariantBuilder *)user_data;
if (!info || !builder) {
- __STC_LOG_FUNC_EXIT__;
- return STC_CANCEL;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_CANCEL; //LCOV_EXCL_LINE
}
__stc_restriction_app_info_builder_add(builder, info);
table_restrictions_info *rule =
(table_restrictions_info *) user_data;
if (rule == NULL) {
- __STC_LOG_FUNC_EXIT__;
- return;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
if (!g_strcmp0(key, "app_id")) {
STC_LOGD("subscriber_id: [%s]", rule->subscriber_id);
} else {
- STC_LOGD("Unknown select rule");
+ STC_LOGD("Unknown select rule"); //LCOV_EXCL_LINE
}
__STC_LOG_FUNC_EXIT__;
rule.rst_state = STC_RESTRICTION_REMOVED;
if (__validate_rstn_rule(&rule, RST_SET) == FALSE) {
- STC_RESTRICTION_DBUS_REPLY_ERROR(invocation,
+ STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
STC_ERROR_INVALID_PARAMETER);
- __STC_LOG_FUNC_EXIT__;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
return TRUE;
}
rule.rst_state = STC_RESTRICTION_EXCLUDED;
if (__validate_rstn_rule(&rule, RST_EXCLUDE) == FALSE) {
- STC_RESTRICTION_DBUS_REPLY_ERROR(invocation,
+ STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
STC_ERROR_INVALID_PARAMETER);
- __STC_LOG_FUNC_EXIT__;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
return TRUE;
}
}
if (__validate_rstn_rule(&rule, RST_UNSET) == FALSE) {
- STC_RESTRICTION_DBUS_REPLY_ERROR(invocation,
+ STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
STC_ERROR_INVALID_PARAMETER);
- __STC_LOG_FUNC_EXIT__;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
return TRUE;
}
__table_restrictions_per_app_cb,
builder);
if (ret < STC_ERROR_NONE) {
- g_variant_builder_unref(builder);
- STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret);
- __STC_LOG_FUNC_EXIT__;
- return TRUE;
+ g_variant_builder_unref(builder); //LCOV_EXCL_LINE
+ STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return TRUE; //LCOV_EXCL_LINE
}
return_parameters = g_variant_new("(ia{sv})", STC_ERROR_NONE, builder);
ret = table_restrictions_foreach(__table_restrictions_foreach_app_cb,
builder);
if (ret < STC_ERROR_NONE) {
- g_variant_builder_unref(builder);
- STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret);
- __STC_LOG_FUNC_EXIT__;
- return TRUE;
+ g_variant_builder_unref(builder); //LCOV_EXCL_LINE
+ STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return TRUE; //LCOV_EXCL_LINE
}
return_parameters = g_variant_new("(iaa{sv})", STC_ERROR_NONE, builder);
ret = table_restrictions_get_restriction_state(app_id, iftype, &state);
if (ret < STC_ERROR_NONE) {
- STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret);
- __STC_LOG_FUNC_EXIT__;
+ STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
return TRUE;
}
table_statistics_select_rule *rule =
(table_statistics_select_rule *) user_data;
if (rule == NULL) {
- __STC_LOG_FUNC_EXIT__;
- return;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
- if (!g_strcmp0(key, "version")) {
- rule->version = g_variant_get_byte(value);
- STC_LOGD("version: [%u]", (unsigned int) rule->version);
-
- } else if (!g_strcmp0(key, "from")) {
+ if (!g_strcmp0(key, "from")) {
rule->from = g_variant_get_uint64(value);
STC_LOGD("from: [%lu]", rule->from);
rule->iftype = g_variant_get_uint16(value);
STC_LOGD("iftype: [%u]", (unsigned int) rule->iftype);
- } else if (!g_strcmp0(key, "granularity")) {
- rule->granularity = g_variant_get_int32(value);
- STC_LOGD("granularity: [%d]", rule->granularity);
-
} else {
- STC_LOGD("Unknown select rule");
+ STC_LOGD("Unknown select rule"); //LCOV_EXCL_LINE
}
__STC_LOG_FUNC_EXIT__;
table_statistics_reset_rule *rule =
(table_statistics_reset_rule *) user_data;
if (rule == NULL) {
- __STC_LOG_FUNC_EXIT__;
- return;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
- if (!g_strcmp0(key, "version")) {
- rule->version = g_variant_get_byte(value);
- STC_LOGD("version: [%u]", (unsigned int) rule->version);
-
- } else if (!g_strcmp0(key, "app_id")) {
+ if (!g_strcmp0(key, "app_id")) {
gsize len = 0;
rule->app_id = g_variant_dup_string(value, &len);
STC_LOGD("app_id: [%s]", rule->app_id);
} else if (!g_strcmp0(key, "from")) {
if (!(rule->interval)) {
- rule->interval = MALLOC0(stc_db_tm_interval_s, 1);
- if (!(rule->interval)) {
- __STC_LOG_FUNC_EXIT__;
- return;
+ rule->interval = MALLOC0(stc_db_tm_interval_s, 1); //LCOV_EXCL_LINE
+ if (!(rule->interval)) { //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
}
} else if (!g_strcmp0(key, "to")) {
if (!(rule->interval)) {
- rule->interval = MALLOC0(stc_db_tm_interval_s, 1);
- if (!(rule->interval)) {
- __STC_LOG_FUNC_EXIT__;
- return;
+ rule->interval = MALLOC0(stc_db_tm_interval_s, 1); //LCOV_EXCL_LINE
+ if (!(rule->interval)) { //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
}
rule->interval->to = g_variant_get_uint64(value);
STC_LOGD("to: [%lu]", rule->interval->to);
- } else if (!g_strcmp0(key, "connection_state")) {
- rule->connection_state = g_variant_get_int32(value);
- STC_LOGD("connection_state: [%d]", rule->connection_state);
-
} else {
- STC_LOGD("Unknown reset rule");
+ STC_LOGD("Unknown reset rule"); //LCOV_EXCL_LINE
}
__STC_LOG_FUNC_EXIT__;
__STC_LOG_FUNC_ENTER__;
if (!builder || !info) {
- __STC_LOG_FUNC_EXIT__;
- return;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
if (info->app_id)
GVariantBuilder sub_builder;
if (!info || !builder) {
- __STC_LOG_FUNC_EXIT__;
- return STC_CANCEL;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_CANCEL; //LCOV_EXCL_LINE
}
g_variant_builder_init(&sub_builder, G_VARIANT_TYPE("a{sv}"));
GVariantBuilder sub_builder;
if (!info || !builder) {
- __STC_LOG_FUNC_EXIT__;
- return STC_CANCEL;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_CANCEL; //LCOV_EXCL_LINE
}
g_variant_builder_init(&sub_builder, G_VARIANT_TYPE("a{sv}"));
g_variant_iter_free(iter);
}
} else {
- STC_LOGD("No selection rule, using default selection rule.");
+ STC_LOGD("No selection rule, using default selection rule."); //LCOV_EXCL_LINE
}
builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
__table_statistics_foreach_app_cb,
builder);
if (ret < STC_ERROR_NONE) {
- g_variant_builder_unref(builder);
- STC_STATISTICS_DBUS_REPLY_ERROR(invocation, ret);
- __STC_LOG_FUNC_EXIT__;
- return TRUE;
+ g_variant_builder_unref(builder); //LCOV_EXCL_LINE
+ STC_STATISTICS_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return TRUE; //LCOV_EXCL_LINE
}
return_parameters = g_variant_new("(iaa{sv})", STC_ERROR_NONE, builder);
g_variant_iter_free(iter);
}
} else {
- STC_LOGD("No selection rule, using default selection rule.");
+ STC_LOGD("No selection rule, using default selection rule."); //LCOV_EXCL_LINE
}
builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
__table_statistics_per_app_cb,
builder);
if (ret < STC_ERROR_NONE) {
- g_variant_builder_unref(builder);
- STC_STATISTICS_DBUS_REPLY_ERROR(invocation, ret);
- __STC_LOG_FUNC_EXIT__;
- return TRUE;
+ g_variant_builder_unref(builder); //LCOV_EXCL_LINE
+ STC_STATISTICS_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return TRUE; //LCOV_EXCL_LINE
}
return_parameters = g_variant_new("(iaa{sv})", STC_ERROR_NONE, builder);
g_variant_iter_free(iter);
}
} else {
- STC_LOGD("No selection rule, using default selection rule.");
+ STC_LOGD("No selection rule, using default selection rule."); //LCOV_EXCL_LINE
}
ret = table_statistics_reset(&rule);
if (ret < STC_ERROR_NONE) {
- STC_STATISTICS_DBUS_REPLY_ERROR(invocation, ret);
- goto handle_error;
+ STC_STATISTICS_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
+ goto handle_error; //LCOV_EXCL_LINE
}
return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-stc-manager C CXX)
+
+SET(GTEST_TEST "gtest-stc-manager")
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(REQUIRES_LIST ${REQUIRES_LIST}
+ glib-2.0
+ gio-2.0
+ gmock
+ dlog
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST})
+
+FOREACH(flag ${GTEST_TEST_PKG_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+FILE(GLOB GTEST_TEST_SRCS *.cpp)
+SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS})
+
+ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_TEST} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl -lgcov)
+
+INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION ${BIN_DIR})
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "gdbus.h"
+
+GDbus::GDbus()
+{
+ this->m_pConnection = NULL;
+ this->m_pCancellable = NULL;
+}
+
+GDbus::~GDbus()
+{
+ GDBusConnection *conn = this->m_pConnection;
+ GCancellable *cancel = this->m_pCancellable;
+
+ if (cancel) {
+ g_cancellable_cancel(cancel);
+ g_object_unref(cancel);
+ cancel = NULL;
+ }
+
+ if (conn) {
+ g_object_unref(conn);
+ conn = NULL;
+ }
+}
+
+error_e GDbus::Create(void)
+{
+ GError *err = NULL;
+
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+ g_type_init();
+#endif
+
+ this->m_pConnection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+ if (this->m_pConnection == NULL) {
+ if (err != NULL) {
+ GLOGD("Failed to connect to the D-BUS daemon [%s]", err->message);
+ g_error_free(err);
+ }
+
+ return ERROR_OPERATION_FAILED;
+ }
+
+ this->m_pCancellable = g_cancellable_new();
+
+ return ERROR_NONE;
+}
+
+error_e GDbus::Destroy(void)
+{
+ g_cancellable_cancel(this->m_pCancellable);
+ g_object_unref(this->m_pCancellable);
+ this->m_pCancellable = NULL;
+
+ g_object_unref(this->m_pConnection);
+ this->m_pConnection = NULL;
+
+ return ERROR_NONE;
+}
+
+GDBusConnection *GDbus::GetConnection(void)
+{
+ return this->m_pConnection;
+}
+
+GCancellable *GDbus::GetCancellable(void)
+{
+ return this->m_pCancellable;
+}
+
+error_e GDbus::ConvertErrorStringToEnum(const char *error)
+{
+ if (NULL != strstr(error, "NoReply"))
+ return ERROR_INVALID_OPERATION;
+ else if (NULL != strstr(error, "Failed"))
+ return ERROR_OPERATION_FAILED;
+ else if (NULL != strstr(error, "UnknownMethod"))
+ return ERROR_INVALID_OPERATION;
+ else if (NULL != strstr(error, "InvalidArguments"))
+ return ERROR_INVALID_PARAMETER;
+ else if (NULL != strstr(error, "AccessDenied"))
+ return ERROR_PERMISSION_DENIED;
+ else if (NULL != strstr(error, "PermissionDenied"))
+ return ERROR_PERMISSION_DENIED;
+ else if (NULL != strstr(error, "NotSupported"))
+ return ERROR_NOT_SUPPORTED;
+ else if (NULL != strstr(error, "InProgress"))
+ return ERROR_IN_PROGRESS;
+
+ return ERROR_OPERATION_FAILED;
+}
+
+GVariant *GDbus::InvokeMethod(const char *dest, const char *path,
+ const char *iface_name, const char *method, GVariant *params, error_e *dbus_error)
+{
+ GError *error = NULL;
+ GVariant *reply = NULL;
+ GDBusConnection *connection = NULL;
+ *dbus_error = ERROR_NONE;
+
+ connection = GetConnection();
+ if (connection == NULL) {
+ GLOGD("GDBusconnection is NULL");
+ *dbus_error = ERROR_NOT_INITIALIZED;
+ return reply;
+ }
+
+ reply = g_dbus_connection_call_sync(connection,
+ dest,
+ path,
+ iface_name,
+ method,
+ params,
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_REPLY_TIMEOUT,
+ GetCancellable(),
+ &error);
+
+ if (reply == NULL) {
+ if (error != NULL) {
+ GLOGD("g_dbus_connection_call_sync() failed "
+ "error [%d: %s]", error->code, error->message);
+ *dbus_error = ConvertErrorStringToEnum(error->message);
+ g_error_free(error);
+ } else {
+ GLOGD("g_dbus_connection_call_sync() failed");
+ *dbus_error = ERROR_OPERATION_FAILED;
+ }
+
+ return NULL;
+ }
+
+ return reply;
+}
+
+error_e GDbus::InvokeMethodNonblock(const char *dest, const char *path,
+ const char *iface_name, const char *method, GVariant *params, int timeout,
+ GAsyncReadyCallback notify_func, void *user_data)
+{
+ GDBusConnection *connection = NULL;
+
+ connection = GetConnection();
+ if (connection == NULL) {
+ GLOGD("GDBusconnection is NULL");
+ return ERROR_NOT_INITIALIZED;
+ }
+
+ g_dbus_connection_call(connection,
+ dest,
+ path,
+ iface_name,
+ method,
+ params,
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ timeout,
+ GetCancellable(),
+ (GAsyncReadyCallback) notify_func,
+ (gpointer)user_data);
+
+ return ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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_MGR_GDBUS_H__
+#define __STC_MGR_GDBUS_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "stcmgr.h"
+
+#define GMAINTIMEOUT 10000
+#define DBUS_REPLY_TIMEOUT (120 * 1000)
+
+#define STC_MGR_SERVICE "net.stc"
+#define STC_MGR_STATISTICS_INTERFACE STC_MGR_SERVICE ".statistics"
+#define STC_MGR_RESTRICTION_INTERFACE STC_MGR_SERVICE ".restriction"
+#define STC_MGR_MANAGER_INTERFACE STC_MGR_SERVICE ".manager"
+
+#define STC_MGR_STATISTICS_PATH "/net/stc/statistics"
+#define STC_MGR_RESTRICTION_PATH "/net/stc/restriction"
+#define STC_MGR_MANAGER_PATH "/net/stc/manager"
+
+#define STC_MGR_METHOD_STATISTICS_INIT "Init"
+#define STC_MGR_METHOD_STATISTICS_GET_PER_APP_ID "Get"
+#define STC_MGR_METHOD_STATISTICS_GET_ALL "GetAll"
+#define STC_MGR_METHOD_STATISTICS_GET_TOTAL "Get"
+#define STC_MGR_METHOD_STATISTICS_RESET "Reset"
+
+#define STC_MGR_METHOD_RESTRICTION_SET "Set"
+#define STC_MGR_METHOD_RESTRICTION_GET_STATUS "GetState"
+#define STC_MGR_METHOD_RESTRICTION_GET_PER_APP_ID "Get"
+#define STC_MGR_METHOD_RESTRICTION_GET_ALL "GetAll"
+#define STC_MGR_METHOD_RESTRICTION_UNSET "Unset"
+#define STC_MGR_METHOD_RESTRICTION_EXCLUDE "Exclude"
+
+#define STC_MGR_METHOD_MANAGER_STOP "Stop"
+
+class GDbus {
+private:
+ GDBusConnection *m_pConnection;
+ GCancellable *m_pCancellable;
+public:
+ GDbus();
+ ~GDbus();
+ error_e Create(void);
+ error_e Destroy(void);
+ GDBusConnection *GetConnection(void);
+ GCancellable *GetCancellable(void);
+ error_e ConvertErrorStringToEnum(const char *error);
+ GVariant *InvokeMethod(const char *dest, const char *path,
+ const char *iface_name, const char *method, GVariant *params, error_e *dbus_error);
+ error_e InvokeMethodNonblock(const char *dest, const char *path,
+ const char *iface_name, const char *method, GVariant *params, int timeout,
+ GAsyncReadyCallback notify_func, void *user_data);
+};
+
+#endif /* __STC_MGR_GDBUS_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "manager.h"
+
+Manager::Manager()
+{
+ Create();
+}
+
+Manager::~Manager()
+{
+ Destroy();
+}
+
+error_e Manager::StopManager(void)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+ int result = 0;
+
+ message = InvokeMethod(STC_MGR_SERVICE,
+ STC_MGR_MANAGER_PATH,
+ STC_MGR_MANAGER_INTERFACE,
+ STC_MGR_METHOD_MANAGER_STOP,
+ NULL,
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(i)", &result);
+ GLOGD("Successfully stop manager [%d]", result);
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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_MGR_MANAGER_H__
+#define __STC_MGR_MANAGER_H__
+
+#include "stcmgr.h"
+#include "gdbus.h"
+
+class Manager : public GDbus {
+private:
+public:
+ Manager();
+ ~Manager();
+ error_e StopManager(void);
+};
+
+
+#endif /* __STC_MGR_MANAGER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "restriction.h"
+
+static GMainLoop *g_pMainLoop = NULL;
+static guint g_nTimeoutId = 0;
+
+static gboolean CallbackTimeut(gpointer data)
+{
+ if (g_pMainLoop)
+ g_main_loop_quit(g_pMainLoop);
+
+ return false;
+}
+
+static void RunMainLoop(void)
+{
+ g_pMainLoop = g_main_loop_new(NULL, false);
+ g_nTimeoutId = g_timeout_add(GMAINTIMEOUT, CallbackTimeut, g_pMainLoop);
+ g_main_loop_run(g_pMainLoop);
+
+ g_source_remove(g_nTimeoutId);
+ g_pMainLoop = NULL;
+}
+
+static void QuitMainLoop(void)
+{
+ if (g_pMainLoop)
+ g_main_loop_quit(g_pMainLoop);
+}
+
+static void AsyncReadyCallback(GObject *source_object,
+ GAsyncResult *res, gpointer user_data)
+{
+ GLOGD("Succeeded to response async callback");
+ QuitMainLoop();
+}
+
+RRule::RRule()
+{
+ this->m_AppID[0] = '\0';
+ this->m_IfaceName[0] = '\0';
+ this->m_IfaceType = IFACE_ALL;
+ this->m_DataLimit = 0;
+ this->m_DataWarnLimit = 0;
+ this->m_RoamingType = ROAMING_DISABLED;
+ this->m_SubscriberID[0] = '\0';
+}
+
+RRule::~RRule()
+{
+}
+
+Restriction::Restriction()
+{
+ Create();
+}
+
+Restriction::~Restriction()
+{
+ Destroy();
+}
+
+error_e Restriction::SetRule(const char *app_id, const char *iface_name,
+ const char *subscriber_id, iface_type_e iface_type,
+ int64_t data_limit, int64_t data_warn_limit,
+ roaming_type_e roaming_type)
+{
+ if (app_id == NULL || strlen(app_id) == 0)
+ this->m_Rule.m_AppID[0] = '\0';
+ else
+ g_strlcpy(this->m_Rule.m_AppID, app_id, APP_ID_LEN);
+
+ if (iface_name == NULL || strlen(iface_name) == 0)
+ this->m_Rule.m_IfaceName[0] = '\0';
+ else
+ g_strlcpy(this->m_Rule.m_IfaceName, iface_name, IFNAME_LEN);
+
+ if (subscriber_id == NULL || strlen(subscriber_id) == 0)
+ this->m_Rule.m_SubscriberID[0] = '\0';
+ else
+ g_strlcpy(this->m_Rule.m_SubscriberID, subscriber_id, SUBSCRIBER_ID_LEN);
+
+ switch(iface_type) {
+ case IFACE_UNKNOWN:
+ case IFACE_DATACALL:
+ case IFACE_WIFI:
+ case IFACE_WIRED:
+ case IFACE_BLUETOOTH:
+ case IFACE_ALL:
+ this->m_Rule.m_IfaceType = iface_type;
+ break;
+ default:
+ return ERROR_INVALID_PARAMETER;
+ }
+
+ switch(roaming_type) {
+ case ROAMING_UNKNOWN:
+ case ROAMING_ENABLED:
+ case ROAMING_DISABLED:
+ this->m_Rule.m_RoamingType = roaming_type;
+ break;
+ default:
+ return ERROR_INVALID_PARAMETER;
+ }
+
+ this->m_Rule.m_DataLimit = data_limit;
+ this->m_Rule.m_DataWarnLimit = data_warn_limit;
+
+ return ERROR_NONE;
+}
+
+void Restriction::MakeRuleParams(GVariant **params)
+{
+ GVariantBuilder *builder;
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+ g_variant_builder_add(builder, "{sv}",
+ RESTRICTION_RULE_APP_ID,
+ g_variant_new_string(this->m_Rule.m_AppID));
+
+ g_variant_builder_add(builder, "{sv}",
+ RESTRICTION_RULE_IFNAME,
+ g_variant_new_string(this->m_Rule.m_IfaceName));
+
+ g_variant_builder_add(builder, "{sv}",
+ RESTRICTION_RULE_IFTYPE,
+ g_variant_new_uint16(this->m_Rule.m_IfaceType));
+
+ g_variant_builder_add(builder, "{sv}",
+ RESTRICTION_RULE_ROAMING,
+ g_variant_new_uint16(this->m_Rule.m_RoamingType));
+
+ g_variant_builder_add(builder, "{sv}",
+ RESTRICTION_RULE_SUBSCRIBER_ID,
+ g_variant_new_string(this->m_Rule.m_SubscriberID));
+
+ g_variant_builder_add(builder, "{sv}",
+ RESTRICTION_RULE_DATA_LIMIT,
+ g_variant_new_int64(this->m_Rule.m_DataLimit));
+
+ g_variant_builder_add(builder, "{sv}",
+ RESTRICTION_RULE_DATA_WARN_LIMIT,
+ g_variant_new_int64(this->m_Rule.m_DataWarnLimit));
+
+ *params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+}
+
+void Restriction::MakeGetParams(GVariant **params)
+{
+ *params = g_variant_new("(s)", this->m_Rule.m_AppID);
+}
+
+void Restriction::MakeStatusParams(GVariant **params)
+{
+ *params = g_variant_new("(si)",
+ this->m_Rule.m_AppID, this->m_Rule.m_IfaceType);
+}
+
+error_e Restriction::SetRstriction(void)
+{
+ GVariant *message = NULL;
+ GVariant *params = NULL;
+ error_e error = ERROR_NONE;
+ int result = 0;
+
+ MakeRuleParams(¶ms);
+
+ message = InvokeMethod(STC_MGR_SERVICE,
+ STC_MGR_RESTRICTION_PATH,
+ STC_MGR_RESTRICTION_INTERFACE,
+ STC_MGR_METHOD_RESTRICTION_SET,
+ params,
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(i)", &result);
+ GLOGD("Succeeded to set restriction [%d]", result);
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e Restriction::ExcludeRstriction(void)
+{
+ GVariant *message = NULL;
+ GVariant *params = NULL;
+ error_e error = ERROR_NONE;
+ int result = 0;
+
+ MakeRuleParams(¶ms);
+
+ message = InvokeMethod(STC_MGR_SERVICE,
+ STC_MGR_RESTRICTION_PATH,
+ STC_MGR_RESTRICTION_INTERFACE,
+ STC_MGR_METHOD_RESTRICTION_EXCLUDE,
+ params,
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(i)", &result);
+ GLOGD("Succeeded to exclude restriction [%d]", result);
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e Restriction::UnsetRstriction(void)
+{
+ GVariant *message = NULL;
+ GVariant *params = NULL;
+ error_e error = ERROR_NONE;
+ int result = 0;
+
+ MakeRuleParams(¶ms);
+
+ message = InvokeMethod(STC_MGR_SERVICE,
+ STC_MGR_RESTRICTION_PATH,
+ STC_MGR_RESTRICTION_INTERFACE,
+ STC_MGR_METHOD_RESTRICTION_UNSET,
+ params,
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(i)", &result);
+ GLOGD("Succeeded to unset restriction [%d]", result);
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e Restriction::GetRstrictionStatus(restriction_status_e *status)
+{
+ GVariant *message = NULL;
+ GVariant *params = NULL;
+ error_e error = ERROR_NONE;
+ int result = 0;
+
+ MakeStatusParams(¶ms);
+
+ message = InvokeMethod(STC_MGR_SERVICE,
+ STC_MGR_RESTRICTION_PATH,
+ STC_MGR_RESTRICTION_INTERFACE,
+ STC_MGR_METHOD_RESTRICTION_GET_STATUS,
+ params,
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(ii)", &result, status);
+ GLOGD("Succeeded to get restriction status [%d:%d]", result, *status);
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
+
+error_e Restriction::GetRstriction(void)
+{
+ GVariant *params = NULL;
+ error_e error = ERROR_NONE;
+
+ MakeGetParams(¶ms);
+
+ error = InvokeMethodNonblock(STC_MGR_SERVICE,
+ STC_MGR_RESTRICTION_PATH,
+ STC_MGR_RESTRICTION_INTERFACE,
+ STC_MGR_METHOD_RESTRICTION_GET_PER_APP_ID,
+ params,
+ DBUS_REPLY_TIMEOUT,
+ AsyncReadyCallback,
+ NULL);
+
+ if (error != ERROR_NONE) {
+ GLOGD("Failed to invoke dbus method nonblock");
+ return error;
+ }
+
+ GLOGD("Succeeded to get restriction per app ID");
+
+ RunMainLoop();
+ return ERROR_NONE;
+}
+
+error_e Restriction::GetAllRstriction(void)
+{
+ error_e error = ERROR_NONE;
+
+ error = InvokeMethodNonblock(STC_MGR_SERVICE,
+ STC_MGR_RESTRICTION_PATH,
+ STC_MGR_RESTRICTION_INTERFACE,
+ STC_MGR_METHOD_RESTRICTION_GET_ALL,
+ NULL,
+ DBUS_REPLY_TIMEOUT,
+ AsyncReadyCallback,
+ NULL);
+
+ if (error != ERROR_NONE) {
+ GLOGD("Failed to invoke dbus method nonblock");
+ return error;
+ }
+
+ GLOGD("Succeeded to get all restriction");
+
+ RunMainLoop();
+ return ERROR_NONE;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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_MGR_RESTRICTION_H__
+#define __STC_MGR_RESTRICTION_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "stcmgr.h"
+#include "gdbus.h"
+
+#define RESTRICTION_RULE_APP_ID "app_id"
+#define RESTRICTION_RULE_IFNAME "ifname"
+#define RESTRICTION_RULE_IFTYPE "iftype"
+#define RESTRICTION_RULE_ROAMING "roaming"
+#define RESTRICTION_RULE_SUBSCRIBER_ID "subscriber_id"
+#define RESTRICTION_RULE_DATA_LIMIT "data_limit"
+#define RESTRICTION_RULE_DATA_WARN_LIMIT "data_warn_limit"
+
+typedef enum {
+ RESTRICTION_UNKNOWN,
+ RESTRICTION_ACTIVATED,
+ RESTRICTION_REMOVED,
+ RESTRICTION_EXCLUDED,
+ RESTRICTION_BACKGROUND,
+ RESTRICTION_LAST_ELEM,
+} restriction_status_e;
+
+class RRule {
+private:
+public:
+ char m_AppID[APP_ID_LEN];
+ char m_IfaceName[IFNAME_LEN];
+ char m_SubscriberID[SUBSCRIBER_ID_LEN];
+ iface_type_e m_IfaceType;
+ int64_t m_DataLimit;
+ int64_t m_DataWarnLimit;
+ roaming_type_e m_RoamingType;
+
+ RRule();
+ ~RRule();
+};
+
+class Restriction : public GDbus {
+private:
+ RRule m_Rule;
+public:
+ Restriction();
+ ~Restriction();
+ error_e SetRule(const char *app_id, const char *iface_name,
+ const char *subscriber_id, iface_type_e iface_type,
+ int64_t data_limit, int64_t data_warn_limit,
+ roaming_type_e roaming_type);
+ void MakeRuleParams(GVariant **params);
+ void MakeGetParams(GVariant **params);
+ void MakeStatusParams(GVariant **params);
+ error_e SetRstriction(void);
+ error_e ExcludeRstriction(void);
+ error_e UnsetRstriction(void);
+ error_e GetRstrictionStatus(restriction_status_e *status);
+ error_e GetRstriction(void);
+ error_e GetAllRstriction(void);
+};
+
+#endif /* __STC_MGR_RESTRICTION_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "statistics.h"
+
+static GMainLoop *g_pMainLoop = NULL;
+static guint g_nTimeoutId = 0;
+
+static gboolean CallbackTimeut(gpointer data)
+{
+ if (g_pMainLoop)
+ g_main_loop_quit(g_pMainLoop);
+
+ return false;
+}
+
+static void RunMainLoop(void)
+{
+ g_pMainLoop = g_main_loop_new(NULL, false);
+ g_nTimeoutId = g_timeout_add(GMAINTIMEOUT, CallbackTimeut, g_pMainLoop);
+ g_main_loop_run(g_pMainLoop);
+
+ g_source_remove(g_nTimeoutId);
+ g_pMainLoop = NULL;
+}
+
+static void QuitMainLoop(void)
+{
+ if (g_pMainLoop)
+ g_main_loop_quit(g_pMainLoop);
+}
+
+static void AsyncReadyCallback(GObject *source_object,
+ GAsyncResult *res, gpointer user_data)
+{
+ GLOGD("Succeeded to response async callback");
+ QuitMainLoop();
+}
+
+SRule::SRule()
+{
+ this->m_IfaceType = IFACE_UNKNOWN;
+ this->m_TimePeriod = TIME_PERIOD_UNKNOWN;
+ this->m_Interval.from = 0;
+ this->m_Interval.to = 0;
+}
+
+SRule::~SRule()
+{
+}
+
+Statistics::Statistics()
+{
+ Create();
+}
+
+Statistics::~Statistics()
+{
+ Destroy();
+}
+
+error_e Statistics::SetRule(const char *app_id, const char *subscriber_id,
+ iface_type_e iface_type, time_t from, time_t to, time_period_e time_period)
+{
+ if (app_id == NULL || strlen(app_id) == 0)
+ this->m_Rule.m_AppID[0] = '\0';
+ else
+ g_strlcpy(this->m_Rule.m_AppID, app_id, APP_ID_LEN);
+
+ if (subscriber_id == NULL || strlen(subscriber_id) == 0)
+ this->m_Rule.m_SubscriberID[0] = '\0';
+ else
+ g_strlcpy(this->m_Rule.m_SubscriberID, subscriber_id, SUBSCRIBER_ID_LEN);
+
+ switch(iface_type) {
+ case IFACE_UNKNOWN:
+ case IFACE_DATACALL:
+ case IFACE_WIFI:
+ case IFACE_WIRED:
+ case IFACE_BLUETOOTH:
+ case IFACE_ALL:
+ this->m_Rule.m_IfaceType = iface_type;
+ break;
+ default:
+ return ERROR_INVALID_PARAMETER;
+ }
+
+ if (from < 0 || to < 0)
+ return ERROR_INVALID_PARAMETER;
+
+ this->m_Rule.m_Interval.from = from;
+ this->m_Rule.m_Interval.to = to;
+
+ switch(time_period) {
+ case TIME_PERIOD_UNKNOWN:
+ case TIME_PERIOD_HOUR:
+ case TIME_PERIOD_DAY:
+ case TIME_PERIOD_WEEK:
+ case TIME_PERIOD_MONTH:
+ this->m_Rule.m_TimePeriod = time_period;
+ break;
+ default:
+ return ERROR_INVALID_PARAMETER;
+ }
+
+ return ERROR_NONE;
+}
+
+time_t Statistics::MakeTime(int year, int mon, int day, int hour, int min)
+{
+ struct tm curr = { 0, };
+ curr.tm_year = year - 1900;
+ curr.tm_mon = mon - 1;
+ curr.tm_mday = day;
+ curr.tm_hour = hour;
+ curr.tm_min = min;
+ return mktime(&curr);
+}
+
+void Statistics::MakeRuleParams(GVariant **params, int mode)
+{
+ GVariantBuilder *builder;
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+ g_variant_builder_add(builder, "{sv}",
+ STATISTICS_RULE_INTERVAL_FROM,
+ g_variant_new_uint64(this->m_Rule.m_Interval.from));
+
+ g_variant_builder_add(builder, "{sv}",
+ STATISTICS_RULE_INTERVAL_TO,
+ g_variant_new_uint64(this->m_Rule.m_Interval.to));
+
+ g_variant_builder_add(builder, "{sv}",
+ STATISTICS_RULE_IFTYPE,
+ g_variant_new_uint16(this->m_Rule.m_IfaceType));
+
+ g_variant_builder_add(builder, "{sv}",
+ STATISTICS_RULE_TIME_PERIOD,
+ g_variant_new_int32(this->m_Rule.m_TimePeriod));
+
+ switch (mode) {
+ case 0: /* reset */
+ g_variant_builder_add(builder, "{sv}",
+ STATISTICS_RULE_APP_ID,
+ g_variant_new_string(this->m_Rule.m_AppID));
+
+ g_variant_builder_add(builder, "{sv}",
+ RESET_RULE_SUBSCRIBER_ID,
+ g_variant_new_string(this->m_Rule.m_SubscriberID));
+
+ *params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
+ break;
+ case 1: /* get app */
+ *params = g_variant_new("(s@a{sv})", this->m_Rule.m_AppID, g_variant_builder_end(builder));
+ break;
+ case 2: /* get total */
+ *params = g_variant_new("(s@a{sv})", "", g_variant_builder_end(builder));
+ break;
+ case 3: /* get all */
+ default:
+ *params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
+ break;
+ }
+
+ g_variant_builder_unref(builder);
+}
+
+error_e Statistics::InitStatistics(void)
+{
+ GVariant *message = NULL;
+ error_e error = ERROR_NONE;
+
+ message = InvokeMethod(STC_MGR_SERVICE,
+ STC_MGR_STATISTICS_PATH,
+ STC_MGR_STATISTICS_INTERFACE,
+ STC_MGR_METHOD_STATISTICS_INIT,
+ NULL,
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ GLOGD("Succeeded to init statistics");
+
+ return ERROR_NONE;
+}
+
+error_e Statistics::GetStatistics(void)
+{
+ GVariant *params = NULL;
+ error_e error = ERROR_NONE;
+
+ MakeRuleParams(¶ms, 1);
+
+ error = InvokeMethodNonblock(STC_MGR_SERVICE,
+ STC_MGR_STATISTICS_PATH,
+ STC_MGR_STATISTICS_INTERFACE,
+ STC_MGR_METHOD_STATISTICS_GET_PER_APP_ID,
+ params,
+ DBUS_REPLY_TIMEOUT,
+ AsyncReadyCallback,
+ NULL);
+
+ if (error != ERROR_NONE) {
+ GLOGD("Failed to invoke dbus method nonblock");
+ return error;
+ }
+
+ RunMainLoop();
+ GLOGD("Succeeded to get statistics per app ID");
+
+ return ERROR_NONE;
+}
+
+error_e Statistics::GetTotalStatistics(void)
+{
+ GVariant *params = NULL;
+ error_e error = ERROR_NONE;
+
+ MakeRuleParams(¶ms, 2);
+
+ error = InvokeMethodNonblock(STC_MGR_SERVICE,
+ STC_MGR_STATISTICS_PATH,
+ STC_MGR_STATISTICS_INTERFACE,
+ STC_MGR_METHOD_STATISTICS_GET_TOTAL,
+ params,
+ DBUS_REPLY_TIMEOUT,
+ AsyncReadyCallback,
+ NULL);
+
+ if (error != ERROR_NONE) {
+ GLOGD("Failed to invoke dbus method nonblock");
+ return error;
+ }
+
+ RunMainLoop();
+ GLOGD("Succeeded to get total statistics");
+
+ return ERROR_NONE;
+}
+
+error_e Statistics::GetAllStatistics(void)
+{
+ GVariant *params = NULL;
+ error_e error = ERROR_NONE;
+
+ MakeRuleParams(¶ms, 3);
+
+ error = InvokeMethodNonblock(STC_MGR_SERVICE,
+ STC_MGR_STATISTICS_PATH,
+ STC_MGR_STATISTICS_INTERFACE,
+ STC_MGR_METHOD_STATISTICS_GET_ALL,
+ params,
+ DBUS_REPLY_TIMEOUT,
+ AsyncReadyCallback,
+ NULL);
+
+ if (error != ERROR_NONE) {
+ GLOGD("Failed to invoke dbus method nonblock");
+ return error;
+ }
+
+ RunMainLoop();
+ GLOGD("Succeeded to get all statistics");
+
+ return ERROR_NONE;
+}
+
+error_e Statistics::ResetStatistics(void)
+{
+ GVariant *message = NULL;
+ GVariant *params = NULL;
+ error_e error = ERROR_NONE;
+ int result = 0;
+
+ MakeRuleParams(¶ms, 0);
+
+ message = InvokeMethod(STC_MGR_SERVICE,
+ STC_MGR_STATISTICS_PATH,
+ STC_MGR_STATISTICS_INTERFACE,
+ STC_MGR_METHOD_STATISTICS_RESET,
+ params,
+ &error);
+
+ if (message == NULL) {
+ GLOGD("Failed to invoke dbus method");
+ return error;
+ }
+
+ g_variant_get(message, "(i)", &result);
+ GLOGD("Succeeded to reset statistics", result);
+ g_variant_unref(message);
+
+ return ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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_MGR_STATISTICS_H__
+#define __STC_MGR_STATISTICS_H__
+
+#include "stcmgr.h"
+#include "gdbus.h"
+
+#define STATISTICS_RULE_APP_ID "app_id"
+#define STATISTICS_RULE_INTERVAL_FROM "from"
+#define STATISTICS_RULE_INTERVAL_TO "to"
+#define STATISTICS_RULE_IFTYPE "iftype"
+#define STATISTICS_RULE_TIME_PERIOD "granularity"
+
+#define RESET_RULE_SUBSCRIBER_ID "subscriber_id"
+
+typedef struct {
+ time_t from;
+ time_t to;
+} time_interval_s;
+
+class SRule {
+private:
+public:
+ char m_AppID[APP_ID_LEN];
+ char m_SubscriberID[SUBSCRIBER_ID_LEN];
+ iface_type_e m_IfaceType;
+ time_period_e m_TimePeriod;
+ time_interval_s m_Interval;
+
+ SRule();
+ ~SRule();
+};
+
+class Statistics : public GDbus {
+private:
+ SRule m_Rule;
+public:
+ Statistics();
+ ~Statistics();
+ error_e SetRule(const char *app_id, const char *subscriber_id,
+ iface_type_e iface_type, time_t from, time_t to, time_period_e time_period);
+ time_t MakeTime(int year, int mon, int day, int hour, int min);
+ void MakeRuleParams(GVariant **params, int mode);
+ error_e InitStatistics(void);
+ error_e GetStatistics(void);
+ error_e GetTotalStatistics(void);
+ error_e GetAllStatistics(void);
+ error_e ResetStatistics(void);
+};
+
+
+#endif /* __STC_MGR_STATISTICS_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 "stcmgr.h"
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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_MGR_H__
+#define __STC_MGR_H__
+
+#include <glib.h>
+
+#define APP_ID_LEN 128
+#define IFNAME_LEN 16
+#define SUBSCRIBER_ID_LEN 128
+
+#ifdef USE_DLOG
+#include <dlog.h>
+#undef LOG_TAG
+#define LOG_TAG "STC_GTEST"
+#define GLOGD(format, args...) LOGD(format, ##args)
+#else
+#define GLOGD(format, args...)
+#endif
+
+typedef enum {
+ ERROR_NONE = 0,
+ ERROR_NOT_PERMITTED = -1,
+ ERROR_OUT_OF_MEMORY = -2,
+ ERROR_PERMISSION_DENIED = -3,
+ ERROR_RESOURCE_BUSY = -4,
+ ERROR_INVALID_OPERATION = -5,
+ ERROR_INVALID_PARAMETER = -6,
+ ERROR_NOT_SUPPORTED = -7,
+ ERROR_OPERATION_FAILED = -8,
+ ERROR_NOT_INITIALIZED = -9,
+ ERROR_ALREADY_INITIALIZED = -10,
+ ERROR_IN_PROGRESS = -11,
+} error_e;
+
+typedef enum {
+ IFACE_UNKNOWN,
+ IFACE_DATACALL,
+ IFACE_WIFI,
+ IFACE_WIRED,
+ IFACE_BLUETOOTH,
+ IFACE_ALL,
+} iface_type_e;
+
+typedef enum {
+ ROAMING_UNKNOWN,
+ ROAMING_ENABLED,
+ ROAMING_DISABLED,
+} roaming_type_e;
+
+typedef enum {
+ TIME_PERIOD_UNKNOWN = 0,
+ TIME_PERIOD_HOUR = 3600,
+ TIME_PERIOD_DAY = 86400,
+ TIME_PERIOD_WEEK = 604800,
+ TIME_PERIOD_MONTH = 2419200,
+} time_period_e;
+
+#endif /* __STC_MGR_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <unistd.h>
+
+#include "unittest.h"
+#include "restriction.h"
+#include "statistics.h"
+#include "manager.h"
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+TEST(StcManager_Statistics, Init_p)
+{
+ error_e ret = ERROR_NONE;
+ Statistics stat;
+
+ ret = stat.InitStatistics();
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Statistics, Get_p)
+{
+ error_e ret = ERROR_NONE;
+ Statistics stat;
+ time_t from = 0;
+ time_t to = 0;
+
+ from = stat.MakeTime(2000, 1, 1, 1, 1);
+ time(&to);
+
+ ret = stat.SetRule("TOTAL_DATACALL",
+ NULL,
+ IFACE_DATACALL,
+ from,
+ to,
+ TIME_PERIOD_DAY);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = stat.GetStatistics();
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = stat.SetRule("TOTAL_WIFI",
+ NULL,
+ IFACE_WIFI,
+ from,
+ to,
+ TIME_PERIOD_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = stat.GetStatistics();
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Statistics, GetAll_p)
+{
+ error_e ret = ERROR_NONE;
+ Statistics stat;
+ time_t from = 0;
+ time_t to = 0;
+
+ from = stat.MakeTime(2000, 1, 1, 1, 1);
+ time(&to);
+
+ ret = stat.SetRule(NULL,
+ NULL,
+ IFACE_UNKNOWN,
+ from,
+ to,
+ TIME_PERIOD_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = stat.GetAllStatistics();
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Statistics, GetTotal_p)
+{
+ error_e ret = ERROR_NONE;
+ Statistics stat;
+ time_t from = 0;
+ time_t to = 0;
+
+ from = stat.MakeTime(2000, 1, 1, 1, 1);
+ time(&to);
+
+ ret = stat.SetRule(NULL,
+ NULL,
+ IFACE_DATACALL,
+ from,
+ to,
+ TIME_PERIOD_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = stat.GetTotalStatistics();
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = stat.SetRule(NULL,
+ NULL,
+ IFACE_WIFI,
+ from,
+ to,
+ TIME_PERIOD_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = stat.GetTotalStatistics();
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Restriction, Set_p)
+{
+ error_e ret = ERROR_NONE;
+ Restriction rest;
+
+ ret = rest.SetRule("Test_tel",
+ "seth_w0",
+ "1234567890abcdefg",
+ IFACE_DATACALL,
+ 0,
+ 0,
+ ROAMING_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.SetRstriction();
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.SetRule("TOTAL_WIFI",
+ "wlan0",
+ NULL,
+ IFACE_WIFI,
+ 2,
+ 1,
+ ROAMING_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.SetRstriction();
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.SetRule("Test_eth",
+ "eth0",
+ NULL,
+ IFACE_WIRED,
+ 100000,
+ 80000,
+ ROAMING_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.SetRstriction();
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Restriction, Exclude_p)
+
+{
+ error_e ret = ERROR_NONE;
+ Restriction rest;
+
+ ret = rest.SetRule("TOTAL_DATACALL",
+ "seth_w0",
+ NULL,
+ IFACE_DATACALL,
+ 0,
+ 0,
+ ROAMING_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.ExcludeRstriction();
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Restriction, Get_p)
+{
+ error_e ret = ERROR_NONE;
+ Restriction rest;
+
+ ret = rest.SetRule("Test_tel",
+ "seth_w0",
+ "1234567890abcdefg",
+ IFACE_DATACALL,
+ 0,
+ 0,
+ ROAMING_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.GetRstriction();
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.SetRule("TOTAL_WIFI",
+ "wlan0",
+ NULL,
+ IFACE_WIFI,
+ 0,
+ 0,
+ ROAMING_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.GetRstriction();
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.SetRule("TOTAL_IPV4",
+ "seth_w0",
+ NULL,
+ IFACE_DATACALL,
+ 0,
+ 0,
+ ROAMING_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.GetRstriction();
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Restriction, GetAll_p)
+{
+ error_e ret = ERROR_NONE;
+ Restriction rest;
+
+ ret = rest.GetAllRstriction();
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Restriction, GetRst_p)
+{
+ error_e ret = ERROR_NONE;
+ Restriction rest;
+ restriction_status_e status = RESTRICTION_UNKNOWN;
+
+ ret = rest.SetRule("Test_tel",
+ "seth_w0",
+ NULL,
+ IFACE_DATACALL,
+ 0,
+ 0,
+ ROAMING_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.GetRstrictionStatus(&status);
+ EXPECT_EQ(ERROR_NONE, ret);
+ EXPECT_LE(RESTRICTION_UNKNOWN, status);
+ EXPECT_GE(RESTRICTION_LAST_ELEM, status);
+
+ ret = rest.SetRule("Test_eth",
+ "eth0",
+ NULL,
+ IFACE_WIRED,
+ 100000,
+ 80000,
+ ROAMING_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.GetRstrictionStatus(&status);
+ EXPECT_EQ(ERROR_NONE, ret);
+ EXPECT_LE(RESTRICTION_UNKNOWN, status);
+ EXPECT_GE(RESTRICTION_LAST_ELEM, status);
+}
+
+TEST(StcManager_Restriction, Unset_p)
+{
+ error_e ret = ERROR_NONE;
+ Restriction rest;
+
+ ret = rest.SetRule("Test_tel",
+ "seth_w0",
+ "1234567890abcdefg",
+ IFACE_DATACALL,
+ 0,
+ 0,
+ ROAMING_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.UnsetRstriction();
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.SetRule("TOTAL_WIFI",
+ "wlan0",
+ NULL,
+ IFACE_WIFI,
+ 2,
+ 1,
+ ROAMING_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.UnsetRstriction();
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.SetRule("Test_eth",
+ "eth0",
+ NULL,
+ IFACE_WIRED,
+ 100000,
+ 80000,
+ ROAMING_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.UnsetRstriction();
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.SetRule("TOTAL_DATACALL",
+ "seth_w0",
+ NULL,
+ IFACE_DATACALL,
+ 0,
+ 0,
+ ROAMING_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = rest.UnsetRstriction();
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Statistics, Reset_p)
+{
+ error_e ret = ERROR_NONE;
+ Statistics stat;
+ time_t from = 0;
+ time_t to = 0;
+
+ from = stat.MakeTime(2000, 1, 1, 1, 1);
+ time(&to);
+
+ ret = stat.SetRule("TOTAL_DATACALL",
+ "1234567890abcdefg",
+ IFACE_DATACALL,
+ from,
+ to,
+ TIME_PERIOD_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = stat.ResetStatistics();
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = stat.SetRule(NULL,
+ NULL,
+ IFACE_UNKNOWN,
+ from,
+ to,
+ TIME_PERIOD_UNKNOWN);
+ EXPECT_EQ(ERROR_NONE, ret);
+
+ ret = stat.ResetStatistics();
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Manager, Stop_p)
+{
+ error_e ret = ERROR_NONE;
+ Manager mgr;
+
+ ret = mgr.StopManager();
+ EXPECT_EQ(ERROR_NONE, ret);
+}
+
+int main(int argc, char **argv)
+{
+ InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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_MGR_UNITTEST_H__
+#define __STC_MGR_UNITTEST_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib.h>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STC_MGR_UNITTEST_H__ */
\ No newline at end of file