4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
29 #define METHOD_REQUEST_SECURE_MOUNT "RequestSecureMount"
30 #define METHOD_REQUEST_SECURE_UNMOUNT "RequestSecureUnmount"
31 #define METHOD_REQUEST_MOUNT "RequestMount"
32 #define METHOD_REQUEST_UNMOUNT "RequestUnmount"
33 #define METHOD_REQUEST_FORMAT "RequestFormat"
35 #define ODE_MOUNT_STATE 1
37 #define FORMAT_TIMEOUT (120*1000)
39 API int mmc_secure_mount(const char *mount_point)
41 if (mount_point == NULL) {
46 arr[0] = (char *)mount_point;
47 return dbus_method_sync(DEVICED_BUS_NAME, DEVICED_PATH_MMC,
48 DEVICED_INTERFACE_MMC, METHOD_REQUEST_SECURE_MOUNT, "s", arr);
51 API int mmc_secure_unmount(const char *mount_point)
53 if (mount_point == NULL) {
58 arr[0] = (char *)mount_point;
59 return dbus_method_sync(DEVICED_BUS_NAME, DEVICED_PATH_MMC,
60 DEVICED_INTERFACE_MMC, METHOD_REQUEST_SECURE_UNMOUNT, "s", arr);
63 static void mount_mmc_cb(void *data, DBusMessage *msg, DBusError *err)
65 struct mmc_contents *mmc_data = (struct mmc_contents*)data;
69 _D("mount_mmc_cb called");
72 _E("no message [%s:%s]", err->name, err->message);
77 dbus_error_init(&r_err);
78 r = dbus_message_get_args(msg, &r_err, DBUS_TYPE_INT32, &mmc_ret, DBUS_TYPE_INVALID);
80 _E("no message [%s:%s]", r_err.name, r_err.message);
81 dbus_error_free(&r_err);
86 _I("Mount State : %d", mmc_ret);
88 // if (mmc_ret == ODE_MOUNT_STATE)
92 (mmc_data->mmc_cb)(mmc_ret, mmc_data->user_data);
95 API int deviced_request_mount_mmc(struct mmc_contents *mmc_data)
97 void (*mount_cb)(void*, DBusMessage*, DBusError*) = NULL;
100 if (mmc_data != NULL && mmc_data->mmc_cb != NULL) {
101 mount_cb = mount_mmc_cb;
105 return dbus_method_async_with_reply(DEVICED_BUS_NAME,
107 DEVICED_INTERFACE_MMC,
108 METHOD_REQUEST_MOUNT,
109 NULL, NULL, mount_cb, -1, data);
112 static void unmount_mmc_cb(void *data, DBusMessage *msg, DBusError *err)
114 struct mmc_contents *mmc_data = (struct mmc_contents*)data;
118 _D("unmount_mmc_cb called");
121 _E("no message [%s:%s]", err->name, err->message);
126 dbus_error_init(&r_err);
127 r = dbus_message_get_args(msg, &r_err, DBUS_TYPE_INT32, &mmc_ret, DBUS_TYPE_INVALID);
129 _E("no message [%s:%s]", r_err.name, r_err.message);
130 dbus_error_free(&r_err);
135 _I("Unmount State : %d", mmc_ret);
138 (mmc_data->mmc_cb)(mmc_ret, mmc_data->user_data);
141 API int deviced_request_unmount_mmc(struct mmc_contents *mmc_data, int option)
145 void (*unmount_cb)(void*, DBusMessage*, DBusError*) = NULL;
148 if (option < 0 || option > 1)
151 if (mmc_data != NULL && mmc_data->mmc_cb != NULL) {
152 unmount_cb = unmount_mmc_cb;
156 snprintf(buf_opt, sizeof(buf_opt), "%d", option);
158 return dbus_method_async_with_reply(DEVICED_BUS_NAME,
160 DEVICED_INTERFACE_MMC,
161 METHOD_REQUEST_UNMOUNT,
162 "i", arr, unmount_cb, -1, data);
165 static void format_mmc_cb(void *data, DBusMessage *msg, DBusError *err)
167 struct mmc_contents *mmc_data = (struct mmc_contents*)data;
171 _D("format_mmc_cb called");
174 _E("no message [%s:%s]", err->name, err->message);
179 dbus_error_init(&r_err);
180 r = dbus_message_get_args(msg, &r_err, DBUS_TYPE_INT32, &mmc_ret, DBUS_TYPE_INVALID);
182 _E("no message [%s:%s]", r_err.name, r_err.message);
183 dbus_error_free(&r_err);
188 _I("Format State : %d", mmc_ret);
191 (mmc_data->mmc_cb)(mmc_ret, mmc_data->user_data);
194 API int deviced_request_format_mmc(struct mmc_contents *mmc_data)
196 return deviced_format_mmc(mmc_data, 1);
199 API int deviced_format_mmc(struct mmc_contents *mmc_data, int option)
203 void (*format_cb)(void*, DBusMessage*, DBusError*) = NULL;
206 if (option < 0 || option > 1)
209 if (mmc_data != NULL && mmc_data->mmc_cb != NULL) {
210 format_cb = format_mmc_cb;
214 snprintf(buf_opt, sizeof(buf_opt), "%d", option);
216 return dbus_method_async_with_reply(DEVICED_BUS_NAME,
218 DEVICED_INTERFACE_MMC,
219 METHOD_REQUEST_FORMAT,
220 "i", arr, format_cb, FORMAT_TIMEOUT, data);