eject execution.
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
%postun
rm -rf %{NETWORK_FW_DATADIR}/*.db
rm -rf %{NETWORK_FW_DATADIR}/*.db-journal
+rm -rf /opt/usr/dbspace/.mdgd.db
+rm -rf /opt/usr/dbspace/.mdgd.db-journal
%files
%manifest %{name}.manifest
int mdgd_db_group_delete(char *group_name);
int mdgd_db_device_delete(char *device_id, char *group_name);
bool mdgd_check_device_exist(char *device_id);
+bool mdgd_check_group_exist(const char *group_name);
#ifdef __cplusplus
}
mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
- sql = sqlite3_mprintf("SELECT count(*) FROM %s WHERE device_id=%Q;", MDGD_DB_DEVICE_TABLE, device_id);
+ sql = sqlite3_mprintf("SELECT count(*) FROM %s WHERE device_id=%Q;",
+ MDGD_DB_DEVICE_TABLE, device_id);
+ if (sql != NULL) {
+ sqlite3_stmt *stmt = NULL;
+
+ ret = sqlite3_prepare_v2(mdgd_ctx->db, sql, strlen(sql), &stmt, NULL);
+ if (ret == SQLITE_OK) {
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ROW) {
+ int count;
+
+ count = sqlite3_column_int(stmt, 0);
+ if (count > 0)
+ result = true;
+ else
+ result = false;
+ } else {
+ LOG_ERR("sqlite3_step failed, [%d:%s]", ret, sqlite3_errmsg(mdgd_ctx->db));
+
+ result = false;
+ }
+
+ sqlite3_finalize(stmt);
+ } else {
+ LOG_ERR("sqlite3_prepare_v2 failed, [%d:%s]", ret, sqlite3_errmsg(mdgd_ctx->db));
+
+ result = false;
+ }
+
+ sqlite3_free(sql);
+ } else {
+ LOG_ERR("sqlite3_mprintf failed");
+
+ result = false;
+ }
+
+ return result;
+}
+
+bool mdgd_check_group_exist(const char *group_name)
+{
+ int ret = 0;
+ bool result = false;
+ int sql_ret;
+ char *sql = NULL;
+ char *error = NULL;
+
+ mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+
+ sql = sqlite3_mprintf("SELECT count(*) FROM %s WHERE group_name=%Q;",
+ MDGD_DB_DEVICE_TABLE, group_name);
if (sql != NULL) {
sqlite3_stmt *stmt = NULL;
g_free(data);
if (mdgd_ctx->ref_count == 0) {
- LOG_DEBUG("No app remaining quit comapnion-manager");
+ LOG_DEBUG("No app remaining quit mdgd");
g_main_loop_quit(mdgd_ctx->main_loop);
}
*
*/
+#include <mdgd_db.h>
#include <mdgd_gdbus_group.h>
/* GDBUS Group Layer */
gboolean group_create(Group *group, GDBusMethodInvocation *invocation,
gchar *group_name, gpointer user_data)
{
- gint result = 0;
+ gint result = MDGD_ERROR_NONE;
LOG_DEBUG("group create called using dbus successful");
- result = mdgd_group_create(group_name);
- if (result == 0)
- mdgd_db_group_insert(group_name);
+ if (mdgd_check_group_exist(group_name))
+ LOG_DEBUG("Group already created");
+ else {
+ result = mdgd_group_create(group_name);
+ if (MDGD_ERROR_NONE == result)
+ mdgd_db_group_insert(group_name);
+ }
group_complete_create(group, invocation, result);
gboolean group_find(Group *group, GDBusMethodInvocation *invocation, gint timeout,
gpointer user_data)
{
- gint result = 0;
+ gint result = MDGD_ERROR_UNKNOWN;
LOG_DEBUG("group find called using dbus successful");
- mdgd_group_find(timeout);
+ result = mdgd_group_find(timeout);
group_complete_find(group, invocation, result);
return TRUE;
gboolean group_get_found_groups(Group *group, GDBusMethodInvocation *invocation,
gpointer user_data)
{
- gint result = 0;
+ gint result = MDGD_ERROR_UNKNOWN;
GVariant *group_data;
LOG_DEBUG("get found groups called using dbus successful");
gboolean group_join(Group *group, GDBusMethodInvocation *invocation,
gpointer user_data)
{
- gint result = 0;
+ gint result = MDGD_ERROR_UNKNOWN;
LOG_DEBUG("join called using dbus successful");
gboolean group_device_find(Group *group, GDBusMethodInvocation *invocation,
gint timeout, gpointer user_data)
{
- int result = 0;
+ int result = MDGD_ERROR_UNKNOWN;
result = mdgd_group_find_mot_enabled_devices(timeout);
gchar *interface_1, int permission_1, gchar *uri_2, gchar *rt_2,
gchar *interface_2, int permission_2, gpointer user_data)
{
- gint result = 0;
+ gint result = MDGD_ERROR_UNKNOWN;
LOG_DEBUG("group device invite called using dbus successful");
/*
gboolean group_device_eject(Group *group, GDBusMethodInvocation *invocation,
gchar *uuid_dev1, gchar *uuid_dev2, gpointer user_data)
{
- gint result = 0;
+ gint result = MDGD_ERROR_UNKNOWN;
LOG_DEBUG("group device eject called using dbus successful");
gboolean group_invite(Group *group, GDBusMethodInvocation *invocation, gchar *group_name,
gchar *uuid, gchar *pin, gpointer user_data)
{
- gint result = 0;
+ gint result = MDGD_ERROR_UNKNOWN;
LOG_DEBUG("group invite called using dbus successful");
- result = mdgd_group_invite(group_name, uuid, pin);
- if (result == 0)
- mdgd_db_device_insert(uuid, group_name);
+ if (mdgd_check_device_exist(uuid)) {
+ result = MDGD_ERROR_ALREADY_REGISTERED;
+ } else {
+ result = mdgd_group_invite(group_name, uuid, pin);
+ if (MDGD_ERROR_NONE == result)
+ mdgd_db_device_insert(uuid, group_name);
+ }
/* Now, for the sake of convenience, we change 'group_complete_invite' to 'group_complete_device_invite'. */
#if 0
gboolean group_eject(Group *group, GDBusMethodInvocation *invocation, gchar *group_name,
gchar *uuid, gpointer user_data)
{
- gint result = 0;
+ gint result = MDGD_ERROR_UNKNOWN;
mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
- if (!mdgd_ctx) {
- LOG_ERR("ctx is null");
- return FALSE;
- }
+ mdgd_check_null_ret_error("mdgd_ctx", mdgd_ctx, FALSE);
- result = mdgd_group_eject(group_name, mdgd_ctx->device_uuid, uuid);
+ if (!mdgd_check_device_exist(uuid)) {
+ result = MDGD_ERROR_ALREADY_REGISTERED;
+ } else {
+ result = mdgd_group_eject(group_name, mdgd_ctx->device_uuid, uuid);
+ }
/* Now, for the sake of convenience, we change 'group_complete_eject' to 'group_complete_device_eject'. */
#if 0
gchar *uri_2, gchar *rt_2, gchar *interface_2, int permission_2,
gpointer user_data)
{
- int ret = 0;
+ int ret = MDGD_ERROR_UNKNOWN;
LOG_DEBUG("pair resource called using dbus successful");
gboolean group_unpair_resource(Group *group, GDBusMethodInvocation *invocation,
gchar *uuid_dev1, gchar *uuid_dev2, gpointer user_data)
{
- int ret = 0;
+ int ret = MDGD_ERROR_UNKNOWN;
LOG_DEBUG("unpair resource called using dbus successful");
gchar *uuid_dev, gchar *addr, int port, GVariant *params,
gpointer user_data)
{
- int ret = 0;
+ int ret = MDGD_ERROR_UNKNOWN;
int length = 0;
int len;
unsigned char *data;
gboolean group_find_mowned_devices(Group *group,
GDBusMethodInvocation *invocation, gint timeout, gpointer user_data)
{
- int ret = 0;
+ int ret = MDGD_ERROR_UNKNOWN;
LOG_DEBUG("find mot owned devices called using dbus successful");
gboolean group_request_create_group(Group *group, GDBusMethodInvocation
*invocation, gchar *uuid, gchar *group_name, gpointer user_data)
{
- int ret = 0;
+ int ret = MDGD_ERROR_UNKNOWN;
LOG_DEBUG("Request Create Group called using dbus successful");
gboolean group_request_invite(Group *group, GDBusMethodInvocation *invocation,
gchar *uuid, gchar *group_name, gchar *target_uuid, gchar *PIN, gpointer user_data)
{
- int ret = 0;
+ int ret = MDGD_ERROR_UNKNOWN;
LOG_DEBUG("Request Invite called using dbus successful");
gboolean group_request_eject(Group *group, GDBusMethodInvocation *invocation,
gchar *uuid, gchar *group_name, gchar *target_uuid, gpointer user_data)
{
- int ret = 0;
+ int ret = MDGD_ERROR_UNKNOWN;
LOG_DEBUG("Request Eject called using dbus successful");
gboolean group_request_delete_group(Group *group,
GDBusMethodInvocation *invocation, gchar *uuid, gchar *group_name, gpointer user_data)
{
- int ret = 0;
+ int ret = MDGD_ERROR_UNKNOWN;
LOG_DEBUG("Request Delete Group called using dbus successful");
GDBusMethodInvocation *invocation, int start,
gpointer user_data)
{
- int ret = 0;
+ int ret = MDGD_ERROR_UNKNOWN;
LOG_DEBUG("Start Myowned device monitor");
case MDGD_REQ_CREATE_GROUP:
LOG_DEBUG("Request create group");
+ result = MDGD_ERROR_NONE;
+
if (rep.getValue("name", group_name)) {
LOG_DEBUG("group_name : %s", group_name.c_str());
- result = mdgd_group_create(group_name.c_str());
- if (result == 0)
- mdgd_db_group_insert(group_name.c_str());
+ if (mdgd_check_group_exist(group_name.c_str()))
+ LOG_DEBUG("Group already created");
+ else {
+ result = mdgd_group_create(group_name.c_str());
+ if (result == 0)
+ mdgd_db_group_insert(group_name.c_str());
+ }
arg = (unsigned char *) g_strdup(group_name.c_str());
arg_len = strlen(group_name.c_str());
}
ret = ma_request_get_ownerid(service, &uuid_str);
if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_get_ownerid = %d", ret);
+ MA_LOGE("Failed to ma_request_get_ownerid [%d][%s]",
+ ret, ma_erro_to_string(ret));
net_ma_complete_get_ownerid(object, invocation, uuid_str, ret);
ret = ma_request_disc_mot_enb_devs(service, timeout);
if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_disc_mot_enb_devs !");
+ MA_LOGE("Failed to ma_request_disc_mot_enb_devs [%d][%s]",
+ ret, ma_erro_to_string(ret));
net_ma_complete_disc_mot_enb_devs(object, invocation, ret);
ret = ma_request_disc_owned_devs(service, timeout);
if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_disc_owned_devs !");
+ MA_LOGE("Failed to ma_request_disc_owned_devs [%d][%s]",
+ ret, ma_erro_to_string(ret));
net_ma_complete_disc_mowned_devs(object, invocation, ret);
ret = ma_request_mot(service, arg_target, arg_pin);
if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_disc_moted_devs !");
+ MA_LOGE("Failed to ma_request_disc_moted_devs [%d][%s]",
+ ret, ma_erro_to_string(ret));
net_ma_complete_mot(object, invocation, ret);
ret = ma_request_prov_acl(service, arg_target, arg_subject, arg_uri, arg_rt,
arg_interface, arg_permission);
if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_prov_acl !");
+ MA_LOGE("Failed to ma_request_prov_acl [%d][%s]",
+ ret, ma_erro_to_string(ret));
net_ma_complete_acl(object, invocation, ret);
ret = ma_request_prov_cred(service, arg_dev1, arg_dev2);
if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_prov_cred !");
+ MA_LOGE("Failed to ma_request_prov_cred [%d][%s]",
+ ret, ma_erro_to_string(ret));
net_ma_complete_cred(object, invocation, ret);
interface_1, permission_1, target_2, subject_2, uri_2,
rt_2, interface_2, permission_2);
if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_pairwise = %d", ret);
+ MA_LOGE("Failed to ma_request_pairwise [%d][%s]",
+ ret, ma_erro_to_string(ret));
net_ma_complete_pairwise(object, invocation, ret);
ret = ma_request_unlink_rsrc(service, uuid_dev1, uuid_dev2);
if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_unpair = %d", ret);
+ MA_LOGE("Failed to ma_request_unpair [%d][%s]",
+ ret, ma_erro_to_string(ret));
net_ma_complete_unpair(object, invocation, ret);
ret = ma_request_remove_subowner(service, arg_target);
if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_remove_subowner !");
+ MA_LOGE("Failed to ma_request_remove_subowner [%d][%s]",
+ ret, ma_erro_to_string(ret));
net_ma_complete_remove_subowner(object, invocation, ret);
ret = ma_request_remove_device(service, arg_target);
if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_remove_subowner !");
+ MA_LOGE("Failed to ma_request_remove_subowner [%d][%s]",
+ ret, ma_erro_to_string(ret));
net_ma_complete_remove_device(object, invocation, ret);
interface_1, permission_1, target_2, subject_2, uri_2,
rt_2, interface_2, permission_2);
if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_pair = %d", ret);
+ MA_LOGE("Failed to ma_request_pair [%d][%s]",
+ ret, ma_erro_to_string(ret));
net_ma_complete_pair(object, invocation, ret);
ret = ma_request_unpair(service, uuid_owner, uuid_owned);
if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_unpair = %d", ret);
+ MA_LOGE("Failed to ma_request_unpair [%d][%s]",
+ ret, ma_erro_to_string(ret));
net_ma_complete_unpair(object, invocation, ret);
while (iter != NULL) {
OicUuid_t *uuid = &iter->doxm->deviceID;
- ma_check_null_ret("uuid", uuid);
+ ma_check_null_ret_error("uuid", uuid, NULL);
g_variant_builder_open(&builder, G_VARIANT_TYPE_VARDICT);
#include <iotivity_config.h>
#include <platform_features.h>
+#include "ma.h"
#include "ma-log.h"
#include "ma-util.h"
}
}
+const char * ma_erro_to_string(ma_error_e err)
+{
+ switch (err) {
+ /* CHECK: List all enum values here */
+ CASE_TO_STR(MA_ERROR_NONE)
+ CASE_TO_STR(MA_ERROR_IO_ERROR)
+ CASE_TO_STR(MA_ERROR_INVALID_PARAMETER)
+ CASE_TO_STR(MA_ERROR_OUT_OF_MEMORY)
+ CASE_TO_STR(MA_ERROR_PERMISSION_DENIED)
+ CASE_TO_STR(MA_ERROR_NOT_SUPPORTED)
+ CASE_TO_STR(MA_ERROR_NO_DATA)
+ CASE_TO_STR(MA_ERROR_OPERATION_FAILED)
+ CASE_TO_STR(MA_ERROR_ALREADY_REGISTERED)
+ CASE_TO_STR(MA_ERROR_IN_PROGRESS)
+ CASE_TO_STR(MA_ERROR_COMM_ERROR)
+ CASE_TO_STR(MA_ERROR_RX)
+ CASE_TO_STR(MA_ERROR_TX)
+ CASE_TO_STR(MA_ERROR_PLUGIN_FAIL)
+ CASE_TO_STR(MA_ERROR_ALREADY_IN_PROGRESS)
+ CASE_TO_STR(MA_ERROR_NOT_STARTED)
+ CASE_TO_STR(MA_ERROR_ALREADY_INITIALIZED)
+ CASE_TO_STR(MA_ERROR_UNKNOWN)
+ default :
+ return "Unknown Error";
+ }
+}
+
OicUuid_t* ma_convert_uuid(gchar *device_id)
{
OicUuid_t *uuid;
const char* ma_ocf_error_to_string(OCStackResult err);
const char* ma_wifi_error_to_string(wifi_manager_error_e err);
+const char * ma_erro_to_string(ma_error_e err);
OicUuid_t* ma_convert_uuid(gchar *device_id);
char * ma_get_readable_uuid(const OicUuid_t* uuid);
#ifdef TEST