[hipl-commit] [tiny] Rev 3523: Changed type of the modular state data structure from 'void' to 'struct

  • From: Tim Just <tim.just@xxxxxxxxxxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Tue, 9 Feb 2010 09:20:34 +0200

Committer: Tim Just <tim.just@xxxxxxxxxxxxxx>
Date: Tue Feb 09 08:15:33 2010 +0100
Revision: 3523
Revision-id: tim.just@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: tiny

Log:
  Changed type of the modular state data structure from 'void' to 'struct
  modular_state'. In this way the compiler can perform type checking.

Modified:
  M  lib/core/state.h
  M  lib/modularization/modularization.c
  M  lib/modularization/modularization.h
  M  test/modularization.c

=== modified file 'lib/core/state.h'
--- lib/core/state.h    2010-01-22 14:29:13 +0000
+++ lib/core/state.h    2010-02-09 07:15:33 +0000
@@ -18,6 +18,8 @@
 
 #endif
 
+#include "lib/modularization/modularization.h"
+
 #define HIP_ENDPOINT_FLAG_PUBKEY           0
 #define HIP_ENDPOINT_FLAG_HIT              1
 #define HIP_ENDPOINT_FLAG_ANON             2
@@ -510,6 +512,9 @@
 
         // Has struct hip_peer_addr_list_item s
         HIP_HASHTABLE *peer_addresses_old;
+
+        /* modular state */
+        struct modular_state *hip_modular_state;
 };
 #endif /* __KERNEL__ */
 

=== modified file 'lib/modularization/modularization.c'
--- lib/modularization/modularization.c 2010-02-08 12:19:13 +0000
+++ lib/modularization/modularization.c 2010-02-09 07:15:33 +0000
@@ -11,13 +11,6 @@
 
 #include "modularization.h"
 #include "lib/core/debug.h"
-#include "lib/core/linkedlist.h"
-
-struct modular_state {
-    hip_ll_t        *item_list;
-    char           **item_names;
-    unsigned int     num_items;
-};
 
 /**
  * hip_init_state
@@ -29,7 +22,7 @@
  *  @return Success = Pointer to the new data structure
  *          Error   = NULL
  **/
-void *hip_init_state(void)
+struct modular_state *hip_init_state(void)
 {
     struct modular_state *state;
 
@@ -65,23 +58,21 @@
  *  @return Success = id (unsigned int) for retrieving the state by number
  *          Error   = -1
  **/
-int hip_add_state_item(void *state, void *state_item, const char *item_name)
+int hip_add_state_item(struct modular_state *state, void *state_item, const 
char *item_name)
 {
-    struct modular_state *localstate = state;
-
     /* Check if identifier already exists */
     if (-1 != hip_get_state_item_id(state, item_name)) {
         return -1;
     }
 
-    hip_ll_add_last(localstate->item_list, state_item);
-
-    localstate->item_names = (char **)realloc(localstate->item_names,
-                             (localstate->num_items + 1) * sizeof(char *));
-
-    localstate->item_names[localstate->num_items++] = strdup(item_name);
-
-    return localstate->num_items-1;
+    hip_ll_add_last(state->item_list, state_item);
+
+    state->item_names = (char **)realloc(state->item_names,
+                             (state->num_items + 1) * sizeof(char *));
+
+    state->item_names[state->num_items++] = strdup(item_name);
+
+    return state->num_items-1;
 }
 
 /**
@@ -95,7 +86,7 @@
  *  @return Success = Pointer to the requested state item (if exists)
  *          Error   = NULL
  **/
-void *hip_get_state_item(void *state, const char *item_name)
+void *hip_get_state_item(struct modular_state *state, const char *item_name)
 {
     unsigned int state_id;
 
@@ -115,10 +106,9 @@
  *  @return Success = Pointer to the requested state item (if exists)
  *          Error   = NULL
  **/
-void *hip_get_state_item_by_id(void *state, const unsigned int id)
+void *hip_get_state_item_by_id(struct modular_state *state, const unsigned int 
id)
 {
-    struct modular_state *localstate = state;
-    return hip_ll_get(localstate->item_list, id);
+    return hip_ll_get(state->item_list, id);
 }
 
 /**
@@ -132,13 +122,12 @@
  *  @return Success = id (index number) of the state item as unsigned int
  *          Error   = -1
  **/
-int hip_get_state_item_id(void *state, const char *item_name)
+int hip_get_state_item_id(struct modular_state *state, const char *item_name)
 {
     unsigned int      i;
-    struct modular_state *localstate = state;
 
-    for (i = 0; i < localstate->num_items; i++) {
-       if (0 == strcmp(item_name, localstate->item_names[i])) {
+    for (i = 0; i < state->num_items; i++) {
+       if (0 == strcmp(item_name, state->item_names[i])) {
            return i;
        }
     }
@@ -153,18 +142,17 @@
  *
  *  @param      state       Pointer to the global state.
  **/
-void hip_free_state(void *state)
+void hip_free_state(struct modular_state *state)
 {
     unsigned int      i;
-    struct modular_state *localstate = state;
-
-    hip_ll_uninit(localstate->item_list, NULL);
-    free(localstate->item_list);
-
-    for (i = 0; i < localstate->num_items; i++) {
-        free(localstate->item_names[i]);
+
+    hip_ll_uninit(state->item_list, NULL);
+    free(state->item_list);
+
+    for (i = 0; i < state->num_items; i++) {
+        free(state->item_names[i]);
     }
 
-    free(localstate->item_names);
-    free(localstate);
+    free(state->item_names);
+    free(state);
 }

=== modified file 'lib/modularization/modularization.h'
--- lib/modularization/modularization.h 2010-02-08 12:19:13 +0000
+++ lib/modularization/modularization.h 2010-02-09 07:15:33 +0000
@@ -9,11 +9,19 @@
 #ifndef HIP_MODULARIZATION_H
 #define HIP_MODULARIZATION_H
 
-void *hip_init_state(void);
-int   hip_add_state_item(void *state, void *state_item, const char *item_name);
-void *hip_get_state_item(void *state, const char *item_name);
-void *hip_get_state_item_by_id(void *state, const unsigned int index);
-int   hip_get_state_item_id(void *state, const char *item_name);
-void  hip_free_state(void *state);
+#include "lib/core/linkedlist.h"
+
+struct modular_state {
+    hip_ll_t        *item_list;
+    char           **item_names;
+    unsigned int     num_items;
+};
+
+struct modular_state *hip_init_state(void);
+int   hip_add_state_item(struct modular_state *state, void *state_item, const 
char *item_name);
+void *hip_get_state_item(struct modular_state *state, const char *item_name);
+void *hip_get_state_item_by_id(struct modular_state *state, const unsigned int 
index);
+int   hip_get_state_item_id(struct modular_state *state, const char 
*item_name);
+void  hip_free_state(struct modular_state *state);
 
 #endif /* HIP_MODULARIZATION_H */

=== modified file 'test/modularization.c'
--- test/modularization.c       2010-02-08 15:40:08 +0000
+++ test/modularization.c       2010-02-09 07:15:33 +0000
@@ -29,8 +29,7 @@
     struct update_state update_state_item1;
     struct ha_state ha_state_item2;
     struct update_state update_state_item2;
-    void *entry1;
-    void *entry2;
+    struct modular_state *entry1, *entry2;
     void *tmp;
     struct update_state *tmp2;

Other related posts:

  • » [hipl-commit] [tiny] Rev 3523: Changed type of the modular state data structure from 'void' to 'struct - Tim Just