From 174c334d699dfe84d777472bced71e613e32dc8c Mon Sep 17 00:00:00 2001 From: Jaeyun Jung Date: Tue, 4 Apr 2023 19:22:30 +0900 Subject: [PATCH] [CodeClean] fix indent Trivial, fix indent and init null to global val. Signed-off-by: Jaeyun Jung --- daemon/gdbus-util.c | 2 +- daemon/main.c | 11 +++--- daemon/model-dbus-impl.cc | 15 +++++---- daemon/modules.c | 2 +- daemon/pipeline-dbus-impl.cc | 79 +++++++++++++++++++++++++++----------------- daemon/pkg-mgr.c | 36 ++++++++++++-------- daemon/service-db.cc | 4 +-- tests/meson.build | 16 ++++----- 8 files changed, 97 insertions(+), 68 deletions(-) diff --git a/daemon/gdbus-util.c b/daemon/gdbus-util.c index e6c9935..6d015d1 100644 --- a/daemon/gdbus-util.c +++ b/daemon/gdbus-util.c @@ -126,7 +126,7 @@ gdbus_get_system_connection (gboolean is_session) g_dbus_sys_conn = g_bus_get_sync (bus_type, NULL, &error); if (g_dbus_sys_conn == NULL) { _E ("cannot connect to the system message bus: %s\n", error->message); - g_clear_error(&error); + g_clear_error (&error); return -ENOSYS; } diff --git a/daemon/main.c b/daemon/main.c index 354dc10..7348827 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -23,7 +23,7 @@ #include "dbus-interface.h" #include "pkg-mgr.h" -static GMainLoop *g_mainloop; +static GMainLoop *g_mainloop = NULL; static gboolean verbose = FALSE; static gboolean is_session = FALSE; @@ -84,10 +84,10 @@ parse_args (gint *argc, gchar ***argv) err = NULL; ret = g_option_context_parse (context, argc, argv, &err); - g_option_context_free(context); + g_option_context_free (context); if (!ret) { _E ("Fail to option parsing: %s", err->message); - g_clear_error(&err); + g_clear_error (&err); return -EINVAL; } @@ -100,7 +100,7 @@ parse_args (gint *argc, gchar ***argv) int main (int argc, char **argv) { - if (parse_args(&argc, &argv)) { + if (parse_args (&argc, &argv)) { return -EINVAL; } @@ -121,8 +121,9 @@ main (int argc, char **argv) gdbus_put_system_connection (); g_main_loop_unref (g_mainloop); + g_mainloop = NULL; - if (pkg_mgr_deinit() < 0) + if (pkg_mgr_deinit () < 0) _W ("cannot finalize package manager"); return 0; diff --git a/daemon/model-dbus-impl.cc b/daemon/model-dbus-impl.cc index cd439b2..f88006b 100644 --- a/daemon/model-dbus-impl.cc +++ b/daemon/model-dbus-impl.cc @@ -36,7 +36,7 @@ gdbus_get_model_instance (void) * @brief Utility function to release DBus proxy of Model interface. */ static void -gdbus_put_model_instance (MachinelearningServiceModel ** instance) +gdbus_put_model_instance (MachinelearningServiceModel **instance) { g_clear_object (instance); } @@ -233,8 +233,7 @@ gdbus_cb_model_get_activated (MachinelearningServiceModel *obj, static gboolean gdbus_cb_model_get_all (MachinelearningServiceModel *obj, GDBusMethodInvocation *invoc, - const gchar *name - ) + const gchar *name) { int ret = 0; MLServiceDB & db = MLServiceDB::getInstance (); @@ -352,7 +351,7 @@ probe_model_module (void *data) } ret = gdbus_connect_signal (g_gdbus_instance, - ARRAY_SIZE(handler_infos), handler_infos); + ARRAY_SIZE (handler_infos), handler_infos); if (ret < 0) { _E ("cannot register callbacks as the dbus method invocation handlers\n ret: %d", ret); @@ -372,7 +371,7 @@ probe_model_module (void *data) out_disconnect: gdbus_disconnect_signal (g_gdbus_instance, - ARRAY_SIZE (handler_infos), handler_infos); + ARRAY_SIZE (handler_infos), handler_infos); out: gdbus_put_model_instance (&g_gdbus_instance); @@ -384,7 +383,9 @@ out: * @brief The callback function for initializing Model Interface module. */ static void -init_model_module (void *data) { } +init_model_module (void *data) +{ +} /** * @brief The callback function for exiting Model Interface module. @@ -393,7 +394,7 @@ static void exit_model_module (void *data) { gdbus_disconnect_signal (g_gdbus_instance, - ARRAY_SIZE (handler_infos), handler_infos); + ARRAY_SIZE (handler_infos), handler_infos); gdbus_put_model_instance (&g_gdbus_instance); } diff --git a/daemon/modules.c b/daemon/modules.c index d47f113..9f85527 100644 --- a/daemon/modules.c +++ b/daemon/modules.c @@ -17,7 +17,7 @@ #include "modules.h" #include "log.h" -static GList *module_head; +static GList *module_head = NULL; /** * @brief Add the specific DBus interface into the Machine Learning agent daemon. diff --git a/daemon/pipeline-dbus-impl.cc b/daemon/pipeline-dbus-impl.cc index cf850cd..102797a 100644 --- a/daemon/pipeline-dbus-impl.cc +++ b/daemon/pipeline-dbus-impl.cc @@ -31,13 +31,14 @@ #include "dbus-interface.h" static MachinelearningServicePipeline *g_gdbus_instance = NULL; -static GHashTable *pipeline_table; +static GHashTable *pipeline_table = NULL; G_LOCK_DEFINE_STATIC (pipeline_table_lock); /** * @brief Structure for pipeline. */ -typedef struct _pipeline { +typedef struct _pipeline +{ GstElement *element; gint64 id; GMutex lock; @@ -48,7 +49,8 @@ typedef struct _pipeline { /** * @brief Internal function to destroy pipeline instances. */ -static void _pipeline_free (gpointer data) +static void +_pipeline_free (gpointer data) { pipeline_s *p; @@ -82,7 +84,7 @@ gdbus_get_pipeline_instance (void) * @brief Put the obtained skeleton object and release the resource. */ static void -gdbus_put_pipeline_instance (MachinelearningServicePipeline ** instance) +gdbus_put_pipeline_instance (MachinelearningServicePipeline **instance) { g_clear_object (instance); } @@ -90,8 +92,10 @@ gdbus_put_pipeline_instance (MachinelearningServicePipeline ** instance) /** * @brief Set the service with given description. Return the call result. */ -static gboolean dbus_cb_core_set_pipeline (MachinelearningServicePipeline *obj, - GDBusMethodInvocation *invoc, const gchar *service_name, const gchar *pipeline_desc, gpointer user_data) +static gboolean +dbus_cb_core_set_pipeline (MachinelearningServicePipeline *obj, + GDBusMethodInvocation *invoc, const gchar *service_name, + const gchar *pipeline_desc, gpointer user_data) { gint result = 0; MLServiceDB &db = MLServiceDB::getInstance (); @@ -123,8 +127,10 @@ static gboolean dbus_cb_core_set_pipeline (MachinelearningServicePipeline *obj, /** * @brief Get the pipeline description of the given service. Return the call result and the pipeline description. */ -static gboolean dbus_cb_core_get_pipeline (MachinelearningServicePipeline *obj, - GDBusMethodInvocation *invoc, const gchar *service_name, gpointer user_data) +static gboolean +dbus_cb_core_get_pipeline (MachinelearningServicePipeline *obj, + GDBusMethodInvocation *invoc, const gchar *service_name, + gpointer user_data) { gint result = 0; std::string stored_pipeline_description; @@ -157,8 +163,10 @@ static gboolean dbus_cb_core_get_pipeline (MachinelearningServicePipeline *obj, /** * @brief Delete the pipeline description of the given service. Return the call result. */ -static gboolean dbus_cb_core_delete_pipeline (MachinelearningServicePipeline *obj, - GDBusMethodInvocation *invoc, const gchar *service_name, gpointer user_data) +static gboolean +dbus_cb_core_delete_pipeline (MachinelearningServicePipeline *obj, + GDBusMethodInvocation *invoc, const gchar *service_name, + gpointer user_data) { gint result = 0; MLServiceDB &db = MLServiceDB::getInstance (); @@ -190,8 +198,10 @@ static gboolean dbus_cb_core_delete_pipeline (MachinelearningServicePipeline *ob /** * @brief Launch the pipeline with given description. Return the call result and its id. */ -static gboolean dbus_cb_core_launch_pipeline (MachinelearningServicePipeline *obj, - GDBusMethodInvocation *invoc, const gchar *service_name, gpointer user_data) +static gboolean +dbus_cb_core_launch_pipeline (MachinelearningServicePipeline *obj, + GDBusMethodInvocation *invoc, const gchar *service_name, + gpointer user_data) { gint result = 0; GError *err = NULL; @@ -224,7 +234,9 @@ static gboolean dbus_cb_core_launch_pipeline (MachinelearningServicePipeline *ob pipeline = gst_parse_launch (stored_pipeline_description.c_str (), &err); if (!pipeline || err) { - _E ("gst_parse_launch with %s Failed. error msg: %s", stored_pipeline_description.c_str (), (err) ? err->message : "unknown reason"); + _E ("gst_parse_launch with %s Failed. error msg: %s", + stored_pipeline_description.c_str (), + (err) ? err->message : "unknown reason"); g_clear_error (&err); if (pipeline) @@ -266,9 +278,9 @@ static gboolean dbus_cb_core_launch_pipeline (MachinelearningServicePipeline *ob /** * @brief Start the pipeline with given id. Return the call result. */ -static gboolean dbus_cb_core_start_pipeline (MachinelearningServicePipeline *obj, - GDBusMethodInvocation *invoc, - gint64 id, gpointer user_data) +static gboolean +dbus_cb_core_start_pipeline (MachinelearningServicePipeline *obj, + GDBusMethodInvocation *invoc, gint64 id, gpointer user_data) { gint result = 0; GstStateChangeReturn sc_ret; @@ -301,9 +313,9 @@ static gboolean dbus_cb_core_start_pipeline (MachinelearningServicePipeline *obj /** * @brief Stop the pipeline with given id. Return the call result. */ -static gboolean dbus_cb_core_stop_pipeline (MachinelearningServicePipeline *obj, - GDBusMethodInvocation *invoc, - gint64 id, gpointer user_data) +static gboolean +dbus_cb_core_stop_pipeline (MachinelearningServicePipeline *obj, + GDBusMethodInvocation *invoc, gint64 id, gpointer user_data) { gint result = 0; GstStateChangeReturn sc_ret; @@ -336,9 +348,9 @@ static gboolean dbus_cb_core_stop_pipeline (MachinelearningServicePipeline *obj, /** * @brief Destroy the pipeline with given id. Return the call result. */ -static gboolean dbus_cb_core_destroy_pipeline (MachinelearningServicePipeline *obj, - GDBusMethodInvocation *invoc, - gint64 id, gpointer user_data) +static gboolean +dbus_cb_core_destroy_pipeline (MachinelearningServicePipeline *obj, + GDBusMethodInvocation *invoc, gint64 id, gpointer user_data) { gint result = 0; pipeline_s *p = NULL; @@ -378,8 +390,9 @@ static gboolean dbus_cb_core_destroy_pipeline (MachinelearningServicePipeline *o /** * @brief Get the state of pipeline with given id. Return the call result and its state. */ -static gboolean dbus_cb_core_get_state (MachinelearningServicePipeline *obj, - GDBusMethodInvocation *invoc, gint64 id, gpointer user_data) +static gboolean +dbus_cb_core_get_state (MachinelearningServicePipeline *obj, + GDBusMethodInvocation *invoc, gint64 id, gpointer user_data) { gint result = 0; GstStateChangeReturn sc_ret; @@ -461,7 +474,8 @@ static struct gdbus_signal_info handler_infos[] = { /** * @brief Probe the D-BUS and connect this module. */ -static int probe_pipeline_module (void *data) +static int +probe_pipeline_module (void *data) { int ret = 0; @@ -503,7 +517,8 @@ out: /** * @brief Initialize this module. */ -static void init_pipeline_module (void *data) +static void +init_pipeline_module (void *data) { GError *err = NULL; @@ -526,11 +541,13 @@ static void init_pipeline_module (void *data) /** * @brief Finalize this module. */ -static void exit_pipeline_module (void *data) +static void +exit_pipeline_module (void *data) { G_LOCK (pipeline_table_lock); g_assert (pipeline_table); /** Internal error */ g_hash_table_destroy (pipeline_table); + pipeline_table = NULL; G_UNLOCK (pipeline_table_lock); gdbus_disconnect_signal (g_gdbus_instance, @@ -539,10 +556,10 @@ static void exit_pipeline_module (void *data) } static const struct module_ops pipeline_ops = { - .name = "pipeline", - .probe = probe_pipeline_module, - .init = init_pipeline_module, - .exit = exit_pipeline_module, + .name = "pipeline", + .probe = probe_pipeline_module, + .init = init_pipeline_module, + .exit = exit_pipeline_module, }; MODULE_OPS_REGISTER (&pipeline_ops) diff --git a/daemon/pkg-mgr.c b/daemon/pkg-mgr.c index 2356eb2..83bbca2 100644 --- a/daemon/pkg-mgr.c +++ b/daemon/pkg-mgr.c @@ -24,21 +24,25 @@ static package_manager_h pkg_mgr = NULL; * @param error the error code when the package manager is failed * @param user_data user data to be passed */ -static void _pkg_mgr_event_cb (const char *type, const char *package, - package_manager_event_type_e event_type, package_manager_event_state_e event_state, - int progress, package_manager_error_e error, void *user_data) +static void +_pkg_mgr_event_cb (const char *type, const char *package, + package_manager_event_type_e event_type, + package_manager_event_state_e event_state, int progress, + package_manager_error_e error, void *user_data) { GDir *dir; gchar *pkg_path = NULL; - _I ("type: %s, package: %s, event_type: %d, event_state: %d", type, package, event_type, event_state); - + _I ("type: %s, package: %s, event_type: %d, event_state: %d", + type, package, event_type, event_state); + if (g_strcmp0 (type, "rpk") != 0) return; /* TODO Define the path of the model & xml files */ pkg_path = g_strdup_printf ("/opt/usr/globalapps/%s/shared/res", package); - if (event_type == PACKAGE_MANAGER_EVENT_TYPE_INSTALL && event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED) { + if (event_type == PACKAGE_MANAGER_EVENT_TYPE_INSTALL && + event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED) { /* TODO Need to register the model into database */ if (g_file_test (pkg_path, G_FILE_TEST_IS_DIR)) { _I ("package path: %s", pkg_path); @@ -51,7 +55,8 @@ static void _pkg_mgr_event_cb (const char *type, const char *package, g_dir_close (dir); } } - } else if (event_type == PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL && event_state == PACKAGE_MANAGER_EVENT_STATE_STARTED) { + } else if (event_type == PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL && + event_state == PACKAGE_MANAGER_EVENT_STATE_STARTED) { /* TODO Need to invalid model */ if (g_file_test (pkg_path, G_FILE_TEST_IS_DIR)) { _I ("package path: %s", pkg_path); @@ -64,7 +69,8 @@ static void _pkg_mgr_event_cb (const char *type, const char *package, g_dir_close (dir); } } - } else if (event_type == PACKAGE_MANAGER_EVENT_TYPE_UPDATE && event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED) { + } else if (event_type == PACKAGE_MANAGER_EVENT_TYPE_UPDATE && + event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED) { /* TODO Need to update database */ if (g_file_test (pkg_path, G_FILE_TEST_IS_DIR)) { _I ("package path: %s", pkg_path); @@ -88,19 +94,22 @@ static void _pkg_mgr_event_cb (const char *type, const char *package, /** * @brief Initialize the package manager handler for the resource package. */ -int pkg_mgr_init(void) +int +pkg_mgr_init (void) { int ret = 0; ret = package_manager_create (&pkg_mgr); if (ret != PACKAGE_MANAGER_ERROR_NONE) { - _E ("package_manager_create() failed: %d", ret); - return -1; + _E ("package_manager_create() failed: %d", ret); + return -1; } /* Monitoring install, uninstall and upgrade events of the resource package. */ ret = package_manager_set_event_status (pkg_mgr, - PACKAGE_MANAGER_STATUS_TYPE_INSTALL|PACKAGE_MANAGER_STATUS_TYPE_UNINSTALL|PACKAGE_MANAGER_STATUS_TYPE_UPGRADE); + PACKAGE_MANAGER_STATUS_TYPE_INSTALL | + PACKAGE_MANAGER_STATUS_TYPE_UNINSTALL | + PACKAGE_MANAGER_STATUS_TYPE_UPGRADE); if (ret != PACKAGE_MANAGER_ERROR_NONE) { _E ("package_manager_set_event_status() failed: %d", ret); return -1; @@ -117,7 +126,8 @@ int pkg_mgr_init(void) /** * @brief Finalize the package manager handler for the resource package. */ -int pkg_mgr_deinit(void) +int +pkg_mgr_deinit (void) { int ret = 0; ret = package_manager_destroy (pkg_mgr); diff --git a/daemon/service-db.cc b/daemon/service-db.cc index b77f79c..789cb1c 100644 --- a/daemon/service-db.cc +++ b/daemon/service-db.cc @@ -308,8 +308,8 @@ MLServiceDB::delete_pipeline (const std::string name) if (sqlite3_prepare_v2 (_db, "DELETE FROM tblPipeline WHERE key = ?1", -1, &res, nullptr) != SQLITE_OK || sqlite3_bind_text (res, 1, key_with_prefix.c_str (), -1, NULL) != SQLITE_OK || sqlite3_step (res) != SQLITE_DONE) { - sqlite3_finalize (res); - throw std::runtime_error ("Failed to delete pipeline description of " + name); + sqlite3_finalize (res); + throw std::runtime_error ("Failed to delete pipeline description of " + name); } sqlite3_finalize (res); diff --git a/tests/meson.build b/tests/meson.build index f9d9c25..a200703 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -30,14 +30,14 @@ if gtest_dep.found() cpp_args: [daemon_cpp_db_key_prefix_arg, '-DDB_PATH="."'] ) - test_db_config_args = declare_dependency( - compile_args: ['-DDB_PATH="."', daemon_cpp_db_key_prefix_arg]) - - service_db_dep_for_test = declare_dependency( - sources: files('../daemon/service-db.cc'), - dependencies: [glib_dep, sqlite_dep, test_db_config_args], - include_directories: nns_ml_agent_incs - ) + test_db_config_args = declare_dependency( + compile_args: ['-DDB_PATH="."', daemon_cpp_db_key_prefix_arg]) + + service_db_dep_for_test = declare_dependency( + sources: files('../daemon/service-db.cc'), + dependencies: [glib_dep, sqlite_dep, test_db_config_args], + include_directories: nns_ml_agent_incs + ) endif subdir('capi') -- 2.7.4