]> rtime.felk.cvut.cz Git - frescor/forb.git/blobdiff - src/request.c
forb: Split forb_port_destroy() to stop and destroy phases
[frescor/forb.git] / src / request.c
index c69295ee854b955c588f35297852fd4d6ac3cadf..53ec150a9dbb51454b1b754313e311c0503c1672 100644 (file)
 /* covered by the GNU Public License.                                    */
 /**************************************************************************/
 
+/**
+ * @file   request.c
+ * @author Michal Sojka <sojkam1@fel.cvut.cz>
+ * @date   Sun Oct 12 19:04:21 2008
+ * 
+ * @brief  Implementation of request handling functions
+ * 
+ * 
+ */
+
 #include <forb/forb-internal.h>
 #include "request.h"
 #include <forb/iop-idl.h>
 
 extern UL_LOG_CUST(ulogd_forb_request);
 
-static inline int forb_request_cmp(CORBA_unsigned_long *a, CORBA_unsigned_long *b)
+static inline int forb_request_cmp(const CORBA_unsigned_long *a,
+                                  const CORBA_unsigned_long *b)
 {
        return (*a<*b) ? -1 :
                ((*a>*b) ? +1 :
                 0);
 }
 
-#if 1
 GAVL_CUST_NODE_INT_IMP(forb_request_nolock /* cust_prefix */,
                       forb_t /* cust_root_t */,
                       forb_request_t /* cust_item_t */,
@@ -71,9 +81,6 @@ GAVL_CUST_NODE_INT_IMP(forb_request_nolock /* cust_prefix */,
                       node /* cust_item_node */,
                       request_id /* cust_item_key */,
                       forb_request_cmp/* cust_cmp_fnc */);
-#else
-#include "request_gavl.inc"
-#endif 
 
 /** 
  * Initializes @a req structure for sending new request to object @a obj.
@@ -84,7 +91,7 @@ GAVL_CUST_NODE_INT_IMP(forb_request_nolock /* cust_prefix */,
  * @return Zero on success, FOSA error code on error.
  */
 int
-forb_request_init(forb_request_t *req, forb_object obj)
+forb_request_init(forb_request_t *req, forb_object obj, char *iface, unsigned method_ind)      
 {
        int ret = 0;
        forb_t *forb = forb_object_to_forb(obj);
@@ -92,13 +99,15 @@ forb_request_init(forb_request_t *req, forb_object obj)
 
        memset(req, 0, sizeof(*req));
        req->obj = obj;
+       req->interface = iface;
+       req->method_ind = method_ind;
 
        fosa_mutex_lock(&forb->request_id_mutex);
        req->request_id = forb->request_id++;
        fosa_mutex_unlock(&forb->request_id_mutex);
 
-       CDR_codec_init_static(&req->cdr_request);
-       bret = CDR_buffer_init(&req->cdr_request, 256, forb_iop_MESSAGE_HEADER_SIZE);
+       FORB_CDR_codec_init_static(&req->cdr_request, obj->orb);
+       bret = FORB_CDR_buffer_init(&req->cdr_request, 4096-8, forb_iop_MESSAGE_HEADER_SIZE);
        if (bret == CORBA_FALSE) {
                return FOSA_ENOMEM;
        }
@@ -110,7 +119,10 @@ forb_request_init(forb_request_t *req, forb_object obj)
 void
 forb_request_destroy(forb_request_t *req)
 {
-       CDR_codec_release_buffer(&req->cdr_request);
+       forb_t *forb = forb_object_to_forb(req->obj);
+
+       forb_request_delete(forb, req);
+       //FORB_CDR_codec_release_buffer(&req->cdr_request);
        forb_syncobj_destroy(&req->reply_ready);
 }
 
@@ -123,7 +135,24 @@ forb_request_signal_reply(forb_request_t *req)
 void
 forb_request_wait_for_reply(forb_request_t *req)
 {
-       forb_syncobj_wait(&req->reply_ready); 
+       fosa_abs_time_t timeout;
+       int ret;
+
+       /* FIXME: What is the appropriate length for timeout? Maybe,
+        * we can specify timeout in forb_env, but since it is
+        * out-direction parameter, we cannot distinguish between
+        * initialized and uninitialized env.timeout.  */
+       fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &timeout);
+       timeout = fosa_abs_time_incr(timeout,
+                                    fosa_msec_to_rel_time(10000));
+
+       ret = forb_syncobj_timedwait(&req->reply_ready, &timeout);
+
+       if (ret == ETIMEDOUT) {
+               req->env->major = FORB_EX_TIMEOUT;
+       } else if (ret) {
+               req->env->major = FORB_EX_INTERNAL;
+       }
 }
 
 void
@@ -133,58 +162,3 @@ forb_request_signal_processed(forb_request_t *req)
        forb_syncobj_signal(req->reply_processed);
 }
 
-/** 
- * Sends REQUEST message to another FORB.
- *
- * The request @a req has to be prepared by
- * forb_iop_prepare_request(). Then, this function adds a message
- * header, connects to the destination FORB and sends the request.
- *
- * If no exception is reported, then the caller must wait for response
- * by calling forb_wait_for_reply().
- * 
- * @param req A request prepared by forb_iop_prepare_request()
- * @param env Environment for returning exceptions
- */
-void
-forb_request_send(forb_request_t *req, CORBA_Environment *env)
-{
-       CORBA_boolean ret;
-       forb_peer_t *peer;
-       size_t size;
-       forb_t *forb = forb_object_to_forb(req->obj);
-       if (!forb) {
-               env->major = FORB_EX_INTERNAL;
-               return;
-       }
-
-       req->env = env;     /* Remember, where to return exceptions */
-
-       ret = forb_iop_prepend_message_header(&req->cdr_request, forb_iop_REQUEST);
-       if (!ret) {
-               /* This should never happen */
-               env->major = FORB_EX_INTERNAL;
-               return;
-       }
-       peer = forb_get_next_hop(forb, &req->obj->server);
-       if (!peer) {
-               char str[50];
-               ul_logerr("Cannot find peer to send request to server: %s\n",
-                         forb_server_id_to_string(str, &req->obj->server, sizeof(str)));
-               env->major = FORB_EX_TRANSIENT;
-               return;
-       }
-       
-       ret = forb_request_insert(forb, req);
-       if (ret <= 0) {
-               ul_logerr("Insert request error %d\n", ret);
-               env->major = FORB_EX_INTERNAL;
-               return;
-       }
-
-       size = forb_proto_send(peer, &req->cdr_request);
-       if (size <= 0) {
-               forb_request_delete(forb, req);
-               env->major = FORB_EX_COMM_FAILURE;
-       }
-}