static MMResourceManager *interface;
-extern int notify_fd;
+extern int notify_fd[2];
static void __gv2c_array(GVariantIter *gv, mm_resource_manager_dmn_res_request_s **c);
-static void _notify_fork_done(void);
+static gboolean on_get_conf(MMResourceManager *interface,
+ GDBusMethodInvocation *invocation, gpointer user_data);
static gboolean on_create_handle(MMResourceManager *interface,
GDBusMethodInvocation *invocation, const gint app_class,
gpointer user_data);
MM_RM_RETVM_IF(interface == NULL,
MM_RESOURCE_MANAGER_ERROR_INVALID_OPERATION,
"Interface cannot be created");
+
+ g_signal_connect(interface, "handle-conf", G_CALLBACK(on_get_conf), NULL);
+ g_signal_connect(interface, "handle-create", G_CALLBACK(on_create_handle), NULL);
+ g_signal_connect(interface, "handle-destroy", G_CALLBACK(on_destroy_handle), NULL);
+ g_signal_connect(interface, "handle-commit", G_CALLBACK(on_commit_handle), NULL);
+
g_bus_own_name(G_BUS_TYPE_SYSTEM, RMD_GDBUS_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired, NULL, NULL, NULL,
NULL);
mm_resource_manager_conf_s *conf;
conf = mm_resource_manager_get_conf();
+
+ MM_RM_RETVM_IF(conf == NULL,
+ MM_RESOURCE_MANAGER_ERROR_INVALID_OPERATION,
+ "mm_resource_manager_conf is NULL");
+
*max_volume = conf->max_volume;
*cond_volume = &conf->condition_volume;
return MM_RESOURCE_MANAGER_ERROR_NONE;
}
+void _mmrm_dmn_notify_fork_done(void)
+{
+ /* Send "string" through the output side of pipe */
+ MM_RM_RETM_IF(write(notify_fd[1], MSG_DONE, strlen(MSG_DONE) + 1) < 0,
+ "Failed to notify parent process that child initialization is done");
+ MM_RM_DEBUG("[%d] Notify parent process that child initialization is done", notify_fd[1]);
+ close(notify_fd[0]);
+ close(notify_fd[1]);
+}
static void __gv2c_array(GVariantIter *gv, mm_resource_manager_dmn_res_request_s **c)
{
*c = rs;
}
-void _notify_fork_done(void)
-{
- /* Send "string" through the output side of pipe */
- MM_RM_RETM_IF(write(notify_fd, MSG_DONE, strlen(MSG_DONE) + 1) < 0,
- "Failed to notify parent process that child initialization is done");
-
- MM_RM_DEBUG("[%d] Notify parent process that child initialization is done", notify_fd);
- close(notify_fd);
-}
-
static gboolean on_get_conf(MMResourceManager *interface,
GDBusMethodInvocation *invocation, gpointer user_data)
{
int i, j;
gint error = 0;
- mm_resource_manager_res_volume *max_volume;
- mm_resource_manager_condition_volume_a *cond_volume;
+ mm_resource_manager_res_volume *max_volume = NULL;
+ mm_resource_manager_condition_volume_a *cond_volume = NULL;
GVariantBuilder *res_type_builder;
GVariantBuilder *res_cond_builder;
GVariant *res_type_conf;
error = _mmrm_dmn_dbus_get_conf(&max_volume, &cond_volume);
res_type_builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
- for (i = 0; i < MM_RESOURCE_MANAGER_RES_TYPE_MAX; i++) {
- g_variant_builder_add_value(res_type_builder,
- g_variant_new("i", max_volume[i]));
- }
+ for (i = 0; i < MM_RESOURCE_MANAGER_RES_TYPE_MAX; i++)
+ g_variant_builder_add_value(res_type_builder, g_variant_new("i", max_volume[i]));
+
res_type_conf = g_variant_builder_end(res_type_builder);
g_variant_builder_unref(res_type_builder);
res_type_builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
for (i = 0; i < MM_RESOURCE_MANAGER_RES_TYPE_MAX; i++) {
res_cond_builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
- for (j = 0; j < MM_RESOURCE_MANAGER_RES_TYPE_COND_MAX; j++) {
- g_variant_builder_add_value(res_cond_builder,
- g_variant_new("i", cond_volume[i][j]));
- }
- g_variant_builder_add_value(res_type_builder,
- g_variant_builder_end(res_cond_builder));
+ for (j = 0; j < MM_RESOURCE_MANAGER_RES_TYPE_COND_MAX; j++)
+ g_variant_builder_add_value(res_cond_builder, g_variant_new("i", cond_volume[i][j]));
+
+ g_variant_builder_add_value(res_type_builder, g_variant_builder_end(res_cond_builder));
g_variant_builder_unref(res_cond_builder);
}
res_cond_conf = g_variant_builder_end(res_type_builder);
g_variant_builder_unref(res_type_builder);
- mmresource_manager_complete_conf(interface, invocation, error,
- res_type_conf, res_cond_conf);
+ mmresource_manager_complete_conf(interface, invocation, error, res_type_conf, res_cond_conf);
return TRUE;
}
for (i = 0; i < acquire_len; i++)
g_variant_builder_add_value(flags_builder, g_variant_new("b", flags[i]));
not_acquired_flags = g_variant_builder_end(flags_builder);
- mmresource_manager_complete_commit(interface, invocation, error,
- not_acquired_flags);
+ mmresource_manager_complete_commit(interface, invocation, error, not_acquired_flags);
g_free(flags);
g_variant_builder_unref(flags_builder);
GError* error = NULL;
MM_RM_DEBUG("name of bus = %s, userID = %d", name, getuid());
- g_signal_connect(interface, "handle-conf", G_CALLBACK(on_get_conf), NULL);
- g_signal_connect(interface, "handle-create", G_CALLBACK(on_create_handle), NULL);
- g_signal_connect(interface, "handle-destroy", G_CALLBACK(on_destroy_handle), NULL);
- g_signal_connect(interface, "handle-commit", G_CALLBACK(on_commit_handle), NULL);
-
if (!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(interface),
connection, RMD_GDBUS_PATH, &error)) {
MM_RM_ERROR("failed to export interface. msg : %s", error->message);
g_error_free(error);
}
-
- _notify_fork_done();
}
g_mutex_lock(&handle->resources_lock);
ret = __dbus_destroy(handle);
if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
- MM_RM_ERROR("Dbus destroy request failed");
+ MM_RM_ERROR("Dbus destroy request failed 0x%x", ret);
__destroy_dispatcher(handle);
g_mutex_lock(&handles_lock);
MM_RESOURCE_MANAGER_CHECK(handle);
g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
ret = __create_resource(handle, type, volume, &resource);
- MM_RM_UNLOCK_RETVM_IF(ret != MM_RESOURCE_MANAGER_ERROR_NONE,
- handle->resources_lock, ret, "Resource cannot be created");
+ MM_RM_UNLOCK2_RETVM_IF(ret != MM_RESOURCE_MANAGER_ERROR_NONE,
+ handle->resources_lock, handles_lock, ret, "Resource cannot be created");
g_ptr_array_add(handle->resources, resource);
*resource_h = resource;
"resource manager #%"PRIu64, *resource_h, type, volume,
_mm_rm_hash64(handle->id));
g_mutex_unlock(&handle->resources_lock);
+ g_mutex_unlock(&handles_lock);
return ret;
}
g_mutex_lock(&handles_lock);
MM_RESOURCE_MANAGER_CHECK(handle);
g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
i = __get_resource_index(handle, resource);
- MM_RM_UNLOCK_RETVM_IF(i == MM_RESOURCE_MANAGER_RES_NOT_FOUND,
- handle->resources_lock,
+ MM_RM_UNLOCK2_RETVM_IF(i == MM_RESOURCE_MANAGER_RES_NOT_FOUND,
+ handle->resources_lock, handles_lock,
MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
"Invalid resource handle");
if (new_volume == resource->volume) {
case MM_RESOURCE_MANAGER_RES_STATE_FOR_ACQUIRE:
if (add_volume > 0) {
ret = __check_resource(handle, resource->type, add_volume);
- MM_RM_UNLOCK_RETVM_IF(ret != MM_RESOURCE_MANAGER_ERROR_NONE,
- handle->resources_lock, ret, "Resource check failed");
+ MM_RM_UNLOCK2_RETVM_IF(ret != MM_RESOURCE_MANAGER_ERROR_NONE,
+ handle->resources_lock, handles_lock, ret, "Resource check failed");
}
resource->volume = new_volume;
break;
case MM_RESOURCE_MANAGER_RES_STATE_FOR_RELEASE:
case MM_RESOURCE_MANAGER_RES_STATE_ACQUIRED:
ret = __create_resource(handle, resource->type, add_volume, &tmp_resource);
- MM_RM_UNLOCK_RETVM_IF(ret != MM_RESOURCE_MANAGER_ERROR_NONE,
- handle->resources_lock, ret, "Resource cannot be created");
+ MM_RM_UNLOCK2_RETVM_IF(ret != MM_RESOURCE_MANAGER_ERROR_NONE,
+ handle->resources_lock, handles_lock, ret, "Resource cannot be created");
tmp_resource->volume = resource->volume;
tmp_resource->state = MM_RESOURCE_MANAGER_RES_STATE_FOR_RELEASE;
MM_RM_INFO("Resource %p is resized for acquire in resource manager #%"PRIu64,
resource_h, _mm_rm_hash64(handle->id));
g_mutex_unlock(&handle->resources_lock);
+ g_mutex_unlock(&handles_lock);
return ret;
}
g_mutex_lock(&handles_lock);
MM_RESOURCE_MANAGER_CHECK(handle);
g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
i = __get_resource_index(handle, resource);
- MM_RM_UNLOCK_RETVM_IF(i == MM_RESOURCE_MANAGER_RES_NOT_FOUND,
- handle->resources_lock,
+ MM_RM_UNLOCK2_RETVM_IF(i == MM_RESOURCE_MANAGER_RES_NOT_FOUND,
+ handle->resources_lock, handles_lock,
MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
"Invalid resource handle");
MM_RM_INFO("Resource %p is marked for release in resource manager #%"PRIu64,
resource_h, _mm_rm_hash64(handle->id));
g_mutex_unlock(&handle->resources_lock);
+ g_mutex_unlock(&handles_lock);
return MM_RESOURCE_MANAGER_ERROR_NONE;
}
g_mutex_lock(&handles_lock);
MM_RESOURCE_MANAGER_CHECK(handle);
g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
for (i = 0; i < handle->resources->len; i++) {
if (!__mark_resource_for_release(handle->resources, i,
- (mm_resource_manager_res_p) handle->resources->pdata[i])) {
+ (mm_resource_manager_res_p) handle->resources->pdata[i]))
i--;
- }
}
MM_RM_INFO("All resources are marked for release in resource manager #%"PRIu64,
_mm_rm_hash64(handle->id));
g_mutex_unlock(&handle->resources_lock);
+ g_mutex_unlock(&handles_lock);
return MM_RESOURCE_MANAGER_ERROR_NONE;
}
g_mutex_lock(&handles_lock);
MM_RESOURCE_MANAGER_CHECK(handle);
g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
i = __get_resource_index(handle, resource);
- MM_RM_UNLOCK_RETVM_IF(i == MM_RESOURCE_MANAGER_RES_NOT_FOUND,
- handle->resources_lock,
+ MM_RM_UNLOCK2_RETVM_IF(i == MM_RESOURCE_MANAGER_RES_NOT_FOUND,
+ handle->resources_lock, handles_lock,
MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
"Invalid resource handle");
MM_RM_INFO("Info structure of resource %p in resource manager #%"PRIu64" is filled",
resource_h, _mm_rm_hash64(handle->id));
g_mutex_unlock(&handle->resources_lock);
+ g_mutex_unlock(&handles_lock);
return MM_RESOURCE_MANAGER_ERROR_NONE;
}
g_mutex_lock(&handles_lock);
MM_RESOURCE_MANAGER_CHECK(handle);
g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
ret = __dbus_commit(handle);
- if (ret == MM_RESOURCE_MANAGER_ERROR_NONE) {
+ if (ret == MM_RESOURCE_MANAGER_ERROR_NONE)
MM_RM_INFO("Changes in resource manager #%"PRIu64" have been committed successfully",
_mm_rm_hash64(handle->id));
- } else {
+ else
MM_RM_ERROR("Dbus commit request failed");
- }
g_mutex_unlock(&handle->resources_lock);
+ g_mutex_unlock(&handles_lock);
return ret;
}
g_mutex_lock(&handles_lock);
MM_RESOURCE_MANAGER_CHECK(handle);
g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
handle->status_cb.cb = cb;
handle->status_cb.user_data = user_data;
g_mutex_unlock(&handle->resources_lock);
+ g_mutex_unlock(&handles_lock);
MM_RM_INFO("Status callback %p in resource manager #%"PRIu64" is set", cb,
_mm_rm_hash64(handle->id));
MM_RM_HASH64(handle_id);
if (handle_id == id) {
g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
for (j = 0; j < handle->resources->len; j++) {
resource = (mm_resource_manager_res_s*)handle->resources->pdata[j];
if (resource->type == type && resource->volume == volume) {
MM_RM_ERROR("Resources cannot be released after release cb");
}
}
- } else {
- g_mutex_unlock(&handles_lock);
}
}
mm_resource_manager_status_e status)
{
g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
if (handle->status_cb.cb) {
((mm_resource_manager_status_cb)handle->status_cb.cb)(handle, status,
handle->status_cb.user_data);
NULL, &error);
MM_RM_RET_IF_GERR(error, "DBus destroy msg cannot be sent");
- MM_RM_DEBUG("Destroy for id - #%"PRIu64" returned error - %d",
- _mm_rm_hash64(handle->id), rm_error);
+ MM_RM_DEBUG("Destroy for id - #%"PRIu64" returned error - %d", _mm_rm_hash64(handle->id), rm_error);
return MM_RESOURCE_MANAGER_ERROR_NONE;
}
release_num++;
break;
default:
- ;
+ break;
}
}
gint arg_resource_type, gint arg_volume)
{
mm_resource_manager_s *handle;
- gboolean unlock = TRUE;
int i;
g_mutex_lock(&handles_lock);
if (handle->dbus_proxy == object) {
__mm_resource_manager_release_callback(handle, arg_id,
arg_resource_type, arg_volume);
- unlock = FALSE;
break;
}
}
-
- if (unlock)
- g_mutex_unlock(&handles_lock);
+ g_mutex_unlock(&handles_lock);
}
static void __dbus_status_callback(MMResourceManager *object, gint arg_status)
{
mm_resource_manager_s *handle;
- gboolean unlock = TRUE;
int i;
g_mutex_lock(&handles_lock);
handle = (mm_resource_manager_s*)handles->pdata[i];
if (handle->dbus_proxy == object) {
__mm_resource_manager_status_callback(handle, arg_status);
- unlock = FALSE;
break;
}
}
-
- if (unlock)
- g_mutex_unlock(&handles_lock);
+ g_mutex_unlock(&handles_lock);
}
static gpointer __dispatcher_thread(gpointer user_data)