#include "core.h"
#include "log.h"
+#include "resource.h"
#include "shared/common.h"
#include "shared/devices.h"
#include "power/power.h"
silent_boot = (retval == 0 && strncmp(bootmode, "silent", sizeof("silent")) == 0);
CRITICAL_LOG("bootmode=%s", bootmode);
+ resource_init();
devices_init(NULL);
ret = gdbus_request_name(handle, DEVICED_BUS_NAME, deviced_dbus_name_acquired, NULL);
g_main_loop_unref(mainloop);
devices_exit(NULL);
+ resource_exit();
+
unload_plugins();
return 0;
--- /dev/null
+/*
+ * deviced
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * 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 <glib.h>
+
+#include <libsyscommon/resource-manager.h>
+#include <system/syscommon-plugin-deviced-common-interface.h>
+
+#define RESOURCE_INSTANCE_UNINITIALIZED (-1)
+/**
+ * Store resource id for each resource type.
+ *
+ * TODO: Currently, there can be only a single instance for each type of resource.
+ * Therefore, it is enough to manage resource id by a single integer for each
+ * resource type. If there would be a case that have multiple instance for a
+ * resource type, however, it is required to fix this data structure to be able
+ * to hold multiple instances by a type, such as list.
+ */
+static int resource_ids[DEVICED_RESOURCE_TYPE_END];
+
+int resource_init(void)
+{
+ int res_type;
+
+ syscommon_resman_init_resource_drivers();
+
+ for (res_type = DEVICED_RESOURCE_TYPE_UNKNOWN + 1; res_type < DEVICED_RESOURCE_TYPE_END; ++res_type) {
+ int ret;
+ int resource_id;
+
+ /* Initialize id by -1, meaning there is no created resource instance. */
+ resource_ids[res_type] = RESOURCE_INSTANCE_UNINITIALIZED;
+
+ ret = syscommon_resman_create_resource(&resource_id, res_type);
+ if (ret < 0)
+ continue;
+
+ resource_ids[res_type] = resource_id;
+ }
+
+ return 0;
+}
+
+void resource_exit(void)
+{
+ int res_type;
+
+ for (res_type = DEVICED_RESOURCE_TYPE_UNKNOWN + 1; res_type < DEVICED_RESOURCE_TYPE_END; ++res_type) {
+ if (resource_ids[res_type] == RESOURCE_INSTANCE_UNINITIALIZED)
+ continue;
+
+ syscommon_resman_delete_resource(resource_ids[res_type]);
+ resource_ids[res_type] = RESOURCE_INSTANCE_UNINITIALIZED;
+ }
+
+ syscommon_resman_exit_resource_drivers();
+}
--- /dev/null
+/*
+ * deviced
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * 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 __DEVICED_RESOURCE_H__
+#define __DEVICED_RESOURCE_H__
+
+int resource_init(void);
+void resource_exit(void);
+
+#endif /* __DEVICED_RESOURCE_H__ */