[hipl-commit] [tiny] Rev 3554: Added hip_unregister_handle_function to libmodularization.

  • From: Tim Just <tim.just@xxxxxxxxxxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Tue, 23 Feb 2010 13:32:58 +0200

Committer: Tim Just <tim.just@xxxxxxxxxxxxxx>
Date: Tue Feb 23 12:31:56 2010 +0100
Revision: 3554
Revision-id: tim.just@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: tiny

Log:
  Added hip_unregister_handle_function to libmodularization.
  
  This function can be used to remove handle functions for a specified 
  combination of packet type and host association state.

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

=== modified file 'lib/modularization/modularization.c'
--- lib/modularization/modularization.c 2010-02-23 10:06:46 +0000
+++ lib/modularization/modularization.c 2010-02-23 11:31:56 +0000
@@ -93,6 +93,51 @@
 }
 
 /**
+ * hip_unregister_handle_function
+ *
+ * Unregister a function for handling of the specified combination from packet
+ * type and host association state.
+ *
+ * @param packet_type The packet type of the control message (RFC 5201, 5.3.)
+ * @param ha_state The host association state (RFC 5201, 4.4.1.)
+ * @param *handle_function Pointer to the function which should be 
unregistered.
+ *
+ * @return Success =  0
+ *         Error   = -1
+ */
+int hip_unregister_handle_function(const uint32_t packet_type,
+                                   const uint32_t ha_state,
+                                   const void *handle_function)
+{
+    int       err, index    = 0;
+    hip_ll_node_t *iter     = NULL;
+
+    HIP_IFEL(packet_type > HIP_MAX_PACKET_TYPE,
+             -1,
+             "Maximum packet type exceeded.\n");
+    HIP_IFEL(ha_state    > HIP_MAX_HA_STATE,
+             -1,
+             "Maximum host association state exceeded.\n");
+
+    if(!handle_functions[packet_type][ha_state]) {
+        HIP_ERROR("Bad combination of packet type and ha_state.\n");
+        return -1;
+    }
+
+    /* Iterate through handle functions until the desired function is found */
+    while((iter = hip_ll_iterate(handle_functions[packet_type][ha_state], 
iter)) != NULL) {
+        if (handle_function == ((struct handle_func_entry *) 
iter->ptr)->handle_func) {
+            hip_ll_del(handle_functions[packet_type][ha_state], index, free);
+            break;
+        }
+        index++;
+    }
+
+out_err:
+    return err;
+}
+
+/**
  * hip_run_handle_functions
  *
  * Run all handle functions for specified combination from packet type and host

=== modified file 'lib/modularization/modularization.h'
--- lib/modularization/modularization.h 2010-02-23 10:06:46 +0000
+++ lib/modularization/modularization.h 2010-02-23 11:31:56 +0000
@@ -40,6 +40,10 @@
                                  const void *handle_function,
                                  const uint32_t priority);
 
+int hip_unregister_handle_function(const uint32_t packet_type,
+                                   const uint32_t ha_state,
+                                   const void *handle_function);
+
 int hip_run_handle_functions(const uint32_t packet_type,
                              const uint32_t ha_state,
                              struct hip_packet_context *ctx);

=== modified file 'test/modularization.c'
--- test/modularization.c       2010-02-22 15:12:49 +0000
+++ test/modularization.c       2010-02-23 11:31:56 +0000
@@ -104,6 +104,10 @@
     hip_register_handle_function(0, 0, &test_function4, 0);
     hip_register_handle_function(0, 0, &test_function5, 0);
 
+    hip_unregister_handle_function(0, 0, &test_function1);
+    hip_unregister_handle_function(0, 0, &test_function3);
+    hip_unregister_handle_function(0, 0, &test_function5);
+
     hip_run_handle_functions(0, 0, NULL);
 
     printf("\n");
@@ -114,6 +118,8 @@
     hip_register_handle_function(1, 1, &test_function4, 1005);
     hip_register_handle_function(1, 1, &test_function5, 1004);
 
+    hip_unregister_handle_function(1, 1, &test_function3);
+
     hip_run_handle_functions(1, 1, NULL);
 
     printf("\n");
@@ -124,6 +130,7 @@
     hip_register_handle_function(16, 16, &test_function4, 2);
     hip_register_handle_function(16, 16, &test_function5, 1);
 
+
     hip_run_handle_functions(16, 16, NULL);
 
     hip_uninit_handle_functions();

Other related posts:

  • » [hipl-commit] [tiny] Rev 3554: Added hip_unregister_handle_function to libmodularization. - Tim Just