#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);
-}
+#include "common.h"
static void AsyncReadyCallback(GObject *source_object,
GAsyncResult *res, gpointer user_data)
{
+ MainLoop *M = (MainLoop *)user_data;
GLOGD("Succeeded to response async callback");
- QuitMainLoop();
+ M->quit();
}
RRule::RRule()
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)
+ roaming_type_e roaming_type, const char *mac)
{
if (app_id == NULL || strlen(app_id) == 0)
this->m_Rule.m_AppID[0] = '\0';
else
g_strlcpy(this->m_Rule.m_SubscriberID, subscriber_id, SUBSCRIBER_ID_LEN);
+ if (mac == NULL || strlen(mac) == 0)
+ this->m_Rule.m_Mac[0] = '\0';
+ else
+ g_strlcpy(this->m_Rule.m_Mac, mac, MAC_LEN);
+
switch(iface_type) {
case IFACE_UNKNOWN:
case IFACE_DATACALL:
RESTRICTION_RULE_DATA_WARN_LIMIT,
g_variant_new_int64(this->m_Rule.m_DataWarnLimit));
+ g_variant_builder_add(builder, "{sv}",
+ RESTRICTION_RULE_MAC,
+ g_variant_new_string(this->m_Rule.m_Mac));
+
+
*params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
g_variant_builder_unref(builder);
}
error_e Restriction::GetRstriction(void)
{
+ MainLoop M;
GVariant *params = NULL;
error_e error = ERROR_NONE;
params,
DBUS_REPLY_TIMEOUT,
AsyncReadyCallback,
- NULL);
+ &M);
if (error != ERROR_NONE) {
GLOGD("Failed to invoke dbus method nonblock");
GLOGD("Succeeded to get restriction per app ID");
- RunMainLoop();
+ M.run(GMAINTIMEOUT);
return ERROR_NONE;
}
error_e Restriction::GetAllRstriction(void)
{
+ MainLoop M;
error_e error = ERROR_NONE;
error = InvokeMethodNonblock(STC_MGR_SERVICE,
NULL,
DBUS_REPLY_TIMEOUT,
AsyncReadyCallback,
- NULL);
+ &M);
if (error != ERROR_NONE) {
GLOGD("Failed to invoke dbus method nonblock");
GLOGD("Succeeded to get all restriction");
- RunMainLoop();
+ M.run(GMAINTIMEOUT);
return ERROR_NONE;
-}
\ No newline at end of file
+}