]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[script] Use access functions instead of directly accessing function objects
authorCharlie Brej <cbrej@cs.man.ac.uk>
Wed, 8 Jul 2009 15:40:32 +0000 (16:40 +0100)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Wed, 8 Jul 2009 15:40:32 +0000 (16:40 +0100)
src/plugins/splash/script/script-lib-plymouth.c
src/plugins/splash/script/script-object.c
src/plugins/splash/script/script-object.h

index 37b0a299d44005cc7df11bb1dac4c45dbba33d97..28c209f8e69a691210e1407dc143186552d1d133 100644 (file)
@@ -45,8 +45,8 @@ static script_return_t plymouth_set_function (script_state_t *state,
 
   script_obj_deref (&obj);
   script_obj_unref (*script_func);
-
-  if (obj->type == SCRIPT_OBJ_TYPE_FUNCTION)
+  
+  if (script_obj_is_function (obj))
     *script_func = obj;
   else
     {
@@ -141,13 +141,11 @@ void script_lib_plymouth_destroy (script_lib_plymouth_data_t *data)
 void script_lib_plymouth_on_refresh (script_state_t             *state,
                                      script_lib_plymouth_data_t *data)
 {
-  script_obj_t *refresh_func_obj = data->script_refresh_func;
-
-  if (refresh_func_obj
-      && (refresh_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION))
+  script_function_t *function = script_obj_as_function (data->script_refresh_func);
+  if (function)
     {
       script_return_t ret = script_execute_function (state,
-                                                     refresh_func_obj->data.function,
+                                                     function,
                                                      NULL);
       script_obj_unref (ret.object);
     }
@@ -158,15 +156,13 @@ void script_lib_plymouth_on_boot_progress (script_state_t             *state,
                                            float                       duration,
                                            float                       progress)
 {
-  script_obj_t *boot_progress_func_obj = data->script_boot_progress_func;
-
-  if (boot_progress_func_obj
-      && (boot_progress_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION))
+  script_function_t *function = script_obj_as_function (data->script_boot_progress_func);
+  if (function)
     {
       script_obj_t *duration_obj = script_obj_new_float (duration);
       script_obj_t *progress_obj = script_obj_new_float (progress);
       script_return_t ret = script_execute_function (state,
-                                                     boot_progress_func_obj->data.function,
+                                                     function,
                                                      duration_obj,
                                                      progress_obj,
                                                      NULL);
@@ -179,13 +175,11 @@ void script_lib_plymouth_on_boot_progress (script_state_t             *state,
 void script_lib_plymouth_on_root_mounted (script_state_t             *state,
                                           script_lib_plymouth_data_t *data)
 {
-  script_obj_t *root_mounted_func_obj = data->script_root_mounted_func;
-
-  if (root_mounted_func_obj
-      && (root_mounted_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION))
+  script_function_t *function = script_obj_as_function (data->script_root_mounted_func);
+  if (function)
     {
       script_return_t ret = script_execute_function (state,
-                                                     root_mounted_func_obj->data.function,
+                                                     function,
                                                      NULL);
       script_obj_unref (ret.object);
     }
@@ -195,14 +189,12 @@ void script_lib_plymouth_on_keyboard_input (script_state_t             *state,
                                             script_lib_plymouth_data_t *data,
                                             const char                 *keyboard_input)
 {
-  script_obj_t *keyboard_input_func_obj = data->script_keyboard_input_func;
-
-  if (keyboard_input_func_obj
-      && (keyboard_input_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION))
+  script_function_t *function = script_obj_as_function (data->script_keyboard_input_func);
+  if (function)
     {
       script_obj_t *keyboard_input_obj = script_obj_new_string (keyboard_input);
       script_return_t ret = script_execute_function (state,
-                                                     keyboard_input_func_obj->data.function,
+                                                     function,
                                                      keyboard_input_obj,
                                                      NULL);
       script_obj_unref (keyboard_input_obj);
@@ -214,14 +206,12 @@ void script_lib_plymouth_on_update_status (script_state_t             *state,
                                            script_lib_plymouth_data_t *data,
                                            const char                 *new_status)
 {
-  script_obj_t *update_status_func_obj = data->script_update_status_func;
-
-  if (update_status_func_obj
-      && (update_status_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION))
+  script_function_t *function = script_obj_as_function (data->script_update_status_func);
+  if (function)
     {
       script_obj_t *new_status_obj = script_obj_new_string (new_status);
       script_return_t ret = script_execute_function (state,
-                                                     update_status_func_obj->data.function,
+                                                     function,
                                                      new_status_obj,
                                                      NULL);
       script_obj_unref (new_status_obj);
@@ -232,13 +222,11 @@ void script_lib_plymouth_on_update_status (script_state_t             *state,
 void script_lib_plymouth_on_display_normal (script_state_t             *state,
                                             script_lib_plymouth_data_t *data)
 {
-  script_obj_t *display_normal_func_obj = data->script_display_normal_func;
-
-  if (display_normal_func_obj
-      && (display_normal_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION))
+  script_function_t *function = script_obj_as_function (data->script_display_normal_func);
+  if (function)
     {
       script_return_t ret = script_execute_function (state,
-                                                     display_normal_func_obj->data.function,
+                                                     function,
                                                      NULL);
       script_obj_unref (ret.object);
     }
@@ -249,15 +237,13 @@ void script_lib_plymouth_on_display_password (script_state_t             *state,
                                               const char                 *prompt,
                                               int                         bullets)
 {
-  script_obj_t *display_password_func_obj = data->script_display_password_func;
-
-  if (display_password_func_obj
-      && (display_password_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION))
+  script_function_t *function = script_obj_as_function (data->script_display_password_func);
+  if (function)
     {
       script_obj_t *prompt_obj = script_obj_new_string (prompt);
       script_obj_t *bullets_obj = script_obj_new_int (bullets);
       script_return_t ret = script_execute_function (state,
-                                                     display_password_func_obj->data.function,
+                                                     function,
                                                      prompt_obj,
                                                      bullets_obj,
                                                      NULL);
@@ -272,15 +258,13 @@ void script_lib_plymouth_on_display_question (script_state_t             *state,
                                               const char                 *prompt,
                                               const char                 *entry_text)
 {
-  script_obj_t *display_question_func_obj = data->script_display_question_func;
-
-  if (display_question_func_obj
-      && (display_question_func_obj->type == SCRIPT_OBJ_TYPE_FUNCTION))
+  script_function_t *function = script_obj_as_function (data->script_display_question_func);
+  if (function)
     {
       script_obj_t *prompt_obj = script_obj_new_string (prompt);
       script_obj_t *entry_text_obj = script_obj_new_string (entry_text);
       script_return_t ret = script_execute_function (state,
-                                                     display_question_func_obj->data.function,
+                                                     function,
                                                      prompt_obj,
                                                      entry_text_obj,
                                                      NULL);
index 9494251929b91a9f9d0fce9b28f380f5a8622a93..c77be86694accec19099635e9ec87e252b10b407 100644 (file)
@@ -438,7 +438,16 @@ char *script_obj_as_string (script_obj_t *obj)              /* reply is strduppe
     }
 
   assert (0);       /* Abort on uncaught */
-  return false;
+  return NULL;
+}
+
+script_function_t *script_obj_as_function (script_obj_t *obj)
+{
+  obj = script_obj_deref_direct (obj);
+  if (obj->type == SCRIPT_OBJ_TYPE_FUNCTION)
+    return obj->data.function;
+  
+  return NULL;
 }
 
 void *script_obj_as_native_of_class (script_obj_t              *obj,
@@ -626,6 +635,16 @@ char *script_obj_hash_get_string (script_obj_t *hash,
   return reply;
 }
 
+script_function_t *script_obj_hash_get_function (script_obj_t *hash,
+                                                 const char   *name)
+{
+  script_obj_t *obj = script_obj_hash_get_element (hash, name);
+  script_function_t *function = script_obj_as_function (obj);
+
+  script_obj_unref (obj);
+  return function;
+}
+
 void *script_obj_hash_get_native_of_class (script_obj_t              *hash,
                                            const char                *name,
                                            script_obj_native_class_t *class)
index 1d584677eb70c60983c4717f0cc8dcc9ec9059fa..355d9f7fb1cffa8c44991c2a0f4eb0608a8aaebb 100644 (file)
@@ -54,7 +54,7 @@ int script_obj_as_int (script_obj_t *obj);
 float script_obj_as_float (script_obj_t *obj);
 bool script_obj_as_bool (script_obj_t *obj);
 char *script_obj_as_string (script_obj_t *obj);
-
+script_function_t *script_obj_as_function (script_obj_t *obj);
 void *script_obj_as_native_of_class (script_obj_t              *obj,
                                      script_obj_native_class_t *class );
 void *script_obj_as_native_of_class_name (script_obj_t *obj,
@@ -84,7 +84,8 @@ bool script_obj_hash_get_bool (script_obj_t *hash,
                                const char   *name);
 char *script_obj_hash_get_string (script_obj_t *hash,
                                   const char   *name);
-
+script_function_t *script_obj_hash_get_function (script_obj_t *hash,
+                                                 const char   *name);
 void *script_obj_hash_get_native_of_class (script_obj_t *hash,
                                            const char   *name,
                                            script_obj_native_class_t *class );