]> rtime.felk.cvut.cz Git - frescor/forb.git/blobdiff - src/port.h
forb: Split forb_port_destroy() to stop and destroy phases
[frescor/forb.git] / src / port.h
index 36f5e7e32e2d84958f0916074d8e95b48f93cf7e..4d0d010c8a6d2bdf9b10bcf34f0f33ad922668f7 100644 (file)
 /* covered by the GNU Public License.                                    */
 /**************************************************************************/
 
+/**
+ * @file   port.h
+ * @author Michal Sojka <sojkam1@fel.cvut.cz>
+ * @date   Sun Oct 12 17:36:39 2008
+ * 
+ * @brief  Declarations of port types and functions.
+ * 
+ * 
+ */
+
 #ifndef FORB_PORT_H
 #define FORB_PORT_H
 
 #include <forb/syncobj.h>
 
 struct forb_proto;
+struct forb_peer;
 
 /**
- * Represents one (of possibly multiple) ports using a specific
- * FORB transport protocol (see ::forb_proto).
+ * Description of a port. Needs to be filled for forb_register_port().
  */
-struct forb_port {
+struct forb_port_desc {
        const struct forb_proto *proto;   /**< Protocol used on this port */
        void *proto_priv;                 /**< Protocol specific data */
+       void *addr;                       /**< Port's address in a protocol specific format. */
+};
+
+/**
+ * Represents one (of possibly multiple) ports using a specific
+ * FORB transport protocol (see ::forb_proto).
+ *
+ * Every port runs its own thread for receiving messages
+ * (forb_iop_receiver_thread()) and another thread
+ * (forb_iop_discovery_thread()) for periodic broadcasting of HELLO
+ * messages to discover peers connected to the same network.
+ */
+typedef struct forb_port {
+       struct forb_port_desc desc;       /**< Description of the port */
        forb_t *forb;                     /**< FORB, this port is registered in. */
        fosa_thread_id_t receiver_thread; /**< The thread running forb_port_receiver_thread() */
        fosa_thread_id_t discovery_thread;/**< The thread for periodic sending HELLO messages */
        forb_syncobj_t hello;             /**< Synchronization object for signaling the discovery thread to send the hello messages now. */
        forb_syncobj_t reply_processed;   /**< Synchronization object for signaling the receiver thread to continue processing after the reply is processed by a stub. */
-       CDR_Codec codec;                  /**< Receiving buffer for receiver thread */
-       void *addr;                       /**< Port's address in a protocol specific format. */
+       FORB_CDR_Codec codec;             /**< Receiving buffer for receiver thread */
        ul_list_node_t node;              /**< Node in forb's port list */
        ul_list_head_t peers;             /**< Peers discovered on this port by discovery protocol */
        bool finish;                      /**< True when the threads should finish their execution, false otherwise. */
-};
 
-typedef struct forb_port forb_port_t;
+       /** Peer discovered by another mean than discovery
+        * protocol. This field may be set by the protocol whenever it
+        * receives a message (e.g. request) from a new peer. This is
+        * to overcome limitations of discovery protocol on unreliable
+        * medium. */
+       struct forb_peer *new_peer;
+} forb_port_t;
 
 UL_LIST_CUST_DEC(forb_port,    /* cust_prefix */
                 forb_t,        /* cust_head_t */
@@ -79,7 +107,8 @@ UL_LIST_CUST_DEC(forb_port,  /* cust_prefix */
                 ports,         /* cust_head_field */
                 node)          /* cust_node_field */
 
-int forb_register_port(forb_t *forb, forb_port_t *port);
+int forb_register_port(forb_orb orb, forb_port_t *port);
+void forb_stop_port(forb_port_t *port);
 void forb_destroy_port(forb_port_t *port);