]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blobdiff - src/forb/src/forb.c
hack: Add fixed reference to wifi_agent to all FORBs
[frescor/frsh-forb.git] / src / forb / src / forb.c
index 79759dad948213d0dc3f15231c243d9983df43c3..98d73b5e7ac46f4dc70a5ba2f128ad6440fc5f69 100644 (file)
@@ -84,6 +84,7 @@
 #ifdef CONFIG_FCB
 #include <fcb.h>
 #include <fcb_contact_info.h>
+#include <wifi_agent.h>
 #endif
 #include <fcntl.h>
 
@@ -165,6 +166,16 @@ void hack_register_fcb(forb_orb orb, forb_port_t *port)
        }
        forb_register_reference(fcb, fres_contract_broker_reg_name);
        forb_object_release(fcb);
+
+       
+
+       forb_object wai = forb_object_new(orb, &WAI_SERVER_ID, 1);
+       if (!fcb) {
+               ul_logerr("Cannot allocate WAI reference\n");
+               return;
+       }
+       forb_register_reference(wai, "net.sourceforge.frsh-forb.wai");
+       forb_object_release(wai);
 }
 #else
 #define hack_register_fcb(orb)
@@ -300,6 +311,29 @@ void forb_destroy(forb_orb orb)
        forb_t *forb = forb_object_to_forb(orb);
        forb_port_t *port;
        forb_regref_t *regref;
+       forb_object obj;
+
+       /* Stop ports to prevent remote requests from coming */
+       ul_list_for_each(forb_port, forb, port) {
+               forb_stop_port(port);
+       }
+
+       /* Wait for executors to finish all requests (and thus drop
+        * all references to peers). This is very inefficient for big
+        * number of objects, but we do not care */
+       gavl_cust_for_each(forb_objects_nolock, forb, obj) {
+               forb_executor_t *executor;
+               executor = forb_object_get_executor(obj);
+               if (executor)
+                       forb_executor_synchronize(executor);
+       }
+
+       /* Destroy ports - this should drop all remaining references
+        * to peers and result in closing of all remote
+        * connections. */
+       ul_list_for_each_cut(forb_port, forb, port) {
+               forb_destroy_port(port);
+       }
 
        pthread_cancel(forb->execution_thread.pthread_id);
        pthread_join(forb->execution_thread.pthread_id, NULL);
@@ -309,9 +343,6 @@ void forb_destroy(forb_orb orb)
                forb_unregister_reference(orb, regref->name.str);
        }
        
-       ul_list_for_each_cut(forb_port, forb, port) {
-               forb_destroy_port(port);
-       }
        forb_object_release(orb);
        forb_free(forb);
 }