]> rtime.felk.cvut.cz Git - frescor/forb.git/commitdiff
Added conversion of object to string + some refactoring
authorMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 23 Sep 2008 15:47:18 +0000 (17:47 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 23 Sep 2008 15:47:18 +0000 (17:47 +0200)
18 files changed:
Makefile.omk
forb-idl.idl
forb-idl/forb-idl-c-headers.c
forb-idl/forb-idl-c-skels.c
forb-idl/forb-idl-c-stubs.c
forb-internal.h
forb.c
forb.h
iop-idl.idl [new file with mode: 0644]
iop.c
iop.h
proto.c
tests/Makefile.omk
tests/object_to_string/Makefile [new file with mode: 0644]
tests/object_to_string/Makefile.omk [new file with mode: 0644]
tests/object_to_string/interface.idl [new file with mode: 0644]
tests/object_to_string/obj2str.c [new file with mode: 0644]
types.idl [new file with mode: 0644]

index 711bdac5f8958896840b039c20625e0fd96c63a8..263a76c5e7e9a70a4753d1191bdf92416774fd26 100644 (file)
@@ -1,38 +1,37 @@
-SUBDIRS = tests-idl tests\r
-EXTRA_RULES_SUBDIRS = forb-idl\r
-\r
-lib_LIBRARIES += forb\r
-forb_SOURCES = forb.c cdr.c sha1.c uuid.c iop.c proto.c syncobj.c request.c\r
-forb_CLIENT_IDL = forb-idl.idl\r
-\r
-lib_LIBRARIES += idltest\r
-idltest_CLIENT_IDL = frescor.idl\r
-\r
-\r
-to_forb_subdir=$(1)->forb/$(strip $(1))\r
-\r
-ifeq ($(CONFIG_FORB_PROTO_UNIX),y)\r
-forb_SOURCES += proto_unix.c\r
-renamed_include_HEADERS += $(call to_forb_subdir, proto_unix.h) \r
-endif\r
-\r
-renamed_include_HEADERS += \\r
-       $(call to_forb_subdir, forb.h) \\r
-       $(call to_forb_subdir, forb-internal.h) \\r
-       $(call to_forb_subdir, basic_types.h) \\r
-       $(call to_forb_subdir, cdr.h) \\r
-       $(call to_forb_subdir, iop.h) \\r
-       $(call to_forb_subdir, uuid.h) \\r
-       $(call to_forb_subdir, syncobj.h) \\r
-       $(call to_forb_subdir, request.h) \\r
-       $(call to_forb_subdir, proto.h)\r
-\r
-renamed_include_GEN_HEADERS = \\r
-       $(call to_forb_subdir,forb-idl.h)\r
-\r
-default_CONFIG = CONFIG_FORB_PROTO_UNIX=y \\r
-                CONFIG_FORB_RECV_BUF_SIZE=4096\r
-\r
-config_include_HEADERS = forb/config.h\r
-config_DEFINES = CONFIG_FORB_PROTO_UNIX \\r
-                CONFIG_FORB_RECV_BUF_SIZE\r
+SUBDIRS = tests-idl tests
+EXTRA_RULES_SUBDIRS = forb-idl
+
+IDL_COMPILER += --pidl
+
+lib_LIBRARIES += forb
+forb_SOURCES = forb.c cdr.c sha1.c uuid.c iop.c proto.c syncobj.c request.c
+forb_CLIENT_IDL = types.idl iop-idl.idl
+
+to_forb_subdir=$(1)->forb/$(strip $(1))
+
+ifeq ($(CONFIG_FORB_PROTO_UNIX),y)
+forb_SOURCES += proto_unix.c
+renamed_include_HEADERS += $(call to_forb_subdir, proto_unix.h) 
+endif
+
+renamed_include_HEADERS += \
+       $(call to_forb_subdir, forb.h) \
+       $(call to_forb_subdir, forb-internal.h) \
+       $(call to_forb_subdir, basic_types.h) \
+       $(call to_forb_subdir, cdr.h) \
+       $(call to_forb_subdir, iop.h) \
+       $(call to_forb_subdir, uuid.h) \
+       $(call to_forb_subdir, syncobj.h) \
+       $(call to_forb_subdir, request.h) \
+       $(call to_forb_subdir, proto.h)
+
+renamed_include_GEN_HEADERS = \
+       $(call to_forb_subdir,iop-idl.h) \
+       $(call to_forb_subdir,types.h)
+
+default_CONFIG = CONFIG_FORB_PROTO_UNIX=y \
+                CONFIG_FORB_RECV_BUF_SIZE=4096
+
+config_include_HEADERS = forb/config.h
+config_DEFINES = CONFIG_FORB_PROTO_UNIX \
+                CONFIG_FORB_RECV_BUF_SIZE
index e4780158f20360f058c12b0c6ba0466081c6dfc1..c8d869a2b034725fed8e3f85502c70c50ad8327b 100644 (file)
@@ -1,59 +1,4 @@
 module forb {
-       typedef long long object_key;
-
-       typedef char uuid[8];
-       struct server_id {
-               uuid uuid;
-       };
-
-       // Inter-ORB protocol
-       module iop {
-               
-               typedef octet message_type;
-
-               const message_type REQUEST = 0;
-               const message_type REPLY   = 1;
-               const message_type HELLO   = 2;
-
-               struct version {
-                       octet major, minor;
-               };
-
-               typedef octet message_flags;
-
-               const message_flags LITTLE_ENDIAN = 1;
-
-               struct message_header {
-                       version       proto_version;
-                        message_type  message_type;
-                       message_flags flags;
-                       unsigned long message_size;
-               };
-               const long MESSAGE_HEADER_SIZE = 8;
-               
-               struct request_header {
-                       unsigned long request_id;
-                       string iface;
-                       object_key objkey;
-                       short method_index;
-                       server_id source; ///< Server ID of request originator
-               };
-
-               typedef unsigned short reply_flags;
-               const reply_flags FLAG_EXCEPTION = 1;
-               struct reply_header {
-                       unsigned long request_id;
-                       reply_flags flags;
-               };
-               const long REPLY_HEADER_SIZE = 8;
-
-               native address;
-
-//             struct hello_header {
-//                     address source;
-//             };
-       };
-       
        __declspec(pidl) interface orb {
                typedef string ObjectId;
                void register_reference(in ObjectId id, in Object object);
index 04ff53549ae65310d5d964cfc06eda5936e222ca..75c08d6db12d136b6eebd66606e9b1d5caf40726 100644 (file)
@@ -146,10 +146,16 @@ forb_idl_output_c_headers (IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
   fprintf(ci->fh, "#ifndef %s%s_H\n", rinfo->header_guard_prefix, ci->c_base_name);
   fprintf(ci->fh, "#define %s%s_H 1\n", rinfo->header_guard_prefix, ci->c_base_name);
 
-  fprintf(ci->fh, "#include <forb/forb.h>\n");
   fprintf(ci->fh, "#define FORB_IDL_SERIAL %d\n", FORB_CONFIG_SERIAL);
-  fprintf(ci->fh, "#include <forb/basic_types.h>\n");
-  fprintf(ci->fh, "#include <idl_native.h> /* Support of native types defined in IDL. This header should be provided by an application. */\n\n");
+
+  if (rinfo->is_pidl) {
+    /* Include only serialization stuff */
+    fprintf(ci->fh, "#include <forb/cdr.h>\n"
+                   "#include <forb/basic_types.h>\n"
+                   "\n");
+  } else {
+    fprintf(ci->fh, "#include <forb/forb-internal.h>\n\n");
+  }
 
   fprintf(ci->fh, "#ifdef __cplusplus\n");
   fprintf(ci->fh, "extern \"C\" {\n");
index 1129077edc2a92dc420b08d99ff5aea01f40efbd..9dadb59a7ba86cc5139f04f8d59ecdab6bb9d7d3 100644 (file)
@@ -363,13 +363,11 @@ cbe_skel_do_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
   fprintf(ci->fh, "%s forb_%s_new(void *instance_data, "
                  "const struct forb_%s_impl *impl, forb_orb orb)\n"
                  "{\n"
-                 "  %s obj = forb_malloc(sizeof(*obj));\n"
+                 "  %s obj = forb_object_new(orb, NULL, 0);\n"
                  "  if (obj) {\n"
                  "    obj->instance_data = instance_data;\n"
                  "    obj->implementation = impl;\n"
                  "    obj->interface = &%s_interface;\n"
-                 "    obj->orb = orb;\n"
-                 "    obj->objkey = (forb_object_key)(unsigned)obj;\n"
                  "  }\n"
                  "  return obj;\n"
          "}\n\n", id, id, id, id, id);
@@ -441,8 +439,7 @@ forb_idl_output_c_skeletons (IDL_tree       tree,
        fprintf (ci->fh, OIDL_C_WARNING);
 /*     fprintf (ci->fh, "#include <string.h>\n"); */
 /*     fprintf (ci->fh, "#define FORB2_STUBS_API\n"); */
-       fprintf (ci->fh, "#include \"%s.h\"\n", ci->base_name);
-       fprintf (ci->fh, "#include <forb/forb-internal.h>\n\n");
+       fprintf (ci->fh, "#include \"%s.h\"\n\n", ci->base_name);
 
        ck_output_poastuff (tree, rinfo, ci);
 }
index ef32dc1c0c6451472ef2c7c83516f0c6fd54bff3..0742cd9836d0bb1a4074201b40e2c1302f28250a 100644 (file)
@@ -186,7 +186,6 @@ forb_idl_output_c_stubs (IDL_tree       tree,
        fprintf (ci->fh, OIDL_C_WARNING);
        fprintf (ci->fh, "#include <string.h>\n");
 /*     fprintf (ci->fh, "#define FORB2_STUBS_API\n"); */
-       fprintf (ci->fh, "#include <forb/forb-idl.h>\n");
        fprintf (ci->fh, "#include <forb/forb-internal.h>\n");
        fprintf (ci->fh, "#include <forb/request.h>\n");
        fprintf (ci->fh, "#include <forb/iop.h>\n");
index f04bebc5a765916496afe951c2c48920ab553009..f804e8e54f1497cc7100c081c7f07005253ae302 100644 (file)
@@ -6,19 +6,25 @@
  * 
  * 
  */
+
 #ifndef FORB_INTERNAL_H
 #define FORB_INTERNAL_H
 
-#include <forb/forb.h>
-#include <forb/forb-idl.h>
 #include <forb/basic_types.h>
+#include <forb/cdr.h>
+#include <forb/forb.h>
+#include <idl_native.h> /* Support of native types defined in
+                        * IDL. This header should be provided by an
+                        * application. */
 #include <forb/uuid.h>
 #include <ul_list.h>
 #include <ul_gavlcust.h>
+#include <forb/forb.h>
 
 /** Object reference structure */
 struct forb_object {
-       /** @name Fields valid only for implementation */ /*@{*/
+       /** @name Fields valid only for implementation */
+       /*@{*/
 
        /** Any data for implementation (in server) */
        void *instance_data;
@@ -33,7 +39,7 @@ struct forb_object {
        /*@}*/
        
        /** Server implementing this object */
-       forb_server_id *server;
+       forb_server_id server;
        /** Object key is just a pointer to the object in the
         * implementation's address space. */
        forb_object_key objkey;
@@ -94,7 +100,6 @@ static inline char *
 forb_server_id_to_string(char *dest, const forb_server_id *server_id, size_t n)
 {
        return forb_uuid_to_string(dest, (forb_uuid_t*)server_id->uuid, n);
-       
 }
 
 
diff --git a/forb.c b/forb.c
index cab7b3bfc4795931371d403d74f17b37da1db5b3..5501cf99f504feaaa0233d9ec81d8fe19f6b7787 100644 (file)
--- a/forb.c
+++ b/forb.c
@@ -1,6 +1,5 @@
-#include <forb/forb.h>
-#include <forb/forb-idl.h>
 #include <forb/forb-internal.h>
+#include <forb/forb.h>
 #include <string.h>
 #include <ul_gavlcust.h>
 #include <forb/uuid.h>
@@ -10,6 +9,7 @@
 #ifdef CONFIG_FORB_PROTO_UNIX
 #include <forb/proto_unix.h>
 #endif
+#include <stdio.h>
 
 forb_orb forb_init(void)
 {
@@ -73,12 +73,47 @@ forb_register_interface(const struct forb_interface *interface)
        //gavl_insert(&type_registry, &interface->node);
 }
 
+/** 
+ * Creates a new object reference.
+ * 
+ * @param orb FORB pseudo object this object reference is handled by.
+ * 
+ * @param server_id Server ID of the FORB, where this object is
+ * implemented or NULL if the object is implemented by @a orb.
+ * 
+ * @param key Key of the remote object or zero if the object is
+ * implemented by @a orb.
+ * 
+ * @return FORB object reference of NULL in case of error.
+ */
+forb_object
+forb_object_new(forb_orb orb,
+              forb_server_id *server_id,
+              forb_object_key key)
+{
+       forb_object obj = forb_malloc(sizeof(*obj));
+       if (obj) {
+               obj->orb = orb;
+               if (key == 0) {
+                       obj->objkey = (forb_object_key)(unsigned)obj;
+               } else {
+                       obj->objkey = key;
+               }
+               if (server_id) {
+                       obj->server = *server_id;
+               } else {
+                       obj->server = forb_obj_to_forb(obj)->server_id;
+               }
+       }
+       return obj;
+}
+       
 /** 
  * Releases all memory associated with a object reference.
  * 
  * @param obj Object reference to release
  */
-void forb_object_release(forb_object obj)
+void forb_object_destroy(forb_object obj)
 {
        forb_free(obj);
 }
@@ -100,3 +135,38 @@ forb_server_id_init(forb_server_id *server_id)
 {
        forb_uuid_generate((forb_uuid_t*)server_id->uuid);
 }
+
+forb_object
+forb_string_to_object(const char *str)
+{
+       return NULL;
+}
+
+/** 
+ * Converts object reference to string.
+ * 
+ * @param obj Object reference to convert.
+ * 
+ * @return String, which must be freed by forb_free() or NULL in case
+ * of error.
+ */
+char *
+forb_object_to_string(const forb_object obj)
+{
+       char *str;
+       size_t s;
+       forb_object_key key;
+       char server_id[65];
+       
+       s = 2*sizeof(forb_server_id)+1+2*sizeof(size_t)+1;
+       str = malloc(s);
+       if (!str) {
+               return NULL;
+       }
+
+       forb_server_id_to_string(server_id, &obj->server, s);
+       key = forb_object_to_key(obj);
+       snprintf(str, s, "%s-%llx", server_id, key);
+
+       return str;
+}
diff --git a/forb.h b/forb.h
index 01482b1032d5f0bde15ef611dfa98f1ba3712ada..568ba561f4f998a0c74e49ed612d2a55144d0b91 100644 (file)
--- a/forb.h
+++ b/forb.h
@@ -13,6 +13,7 @@
 
 #include <forb/basic_types.h>
 #include <forb/cdr.h>
+#include <forb/types.h>
 #include <fosa.h>
 
 /**
@@ -102,12 +103,26 @@ void forb_destroy(forb_orb orb);
 #define CORBA_malloc(size) forb_malloc(size)
 #define CORBA_free(ptr) forb_free(ptr)
 
+forb_object
+forb_object_new(forb_orb orb,
+              forb_server_id *server_id,
+              forb_object_key key);
+void
+forb_object_destroy(forb_object obj);
+
 void
 forb_register_reference(const char *id, forb_object object);
 
 forb_object
 forb_resolve_reference(const char *id);
 
-void forb_register_interface(const struct forb_interface *interface);
+void
+forb_register_interface(const struct forb_interface *interface);
+
+forb_object
+forb_string_to_object(const char *str);
+
+char *
+forb_object_to_string(const forb_object obj);
 
 #endif
diff --git a/iop-idl.idl b/iop-idl.idl
new file mode 100644 (file)
index 0000000..9a9e924
--- /dev/null
@@ -0,0 +1,51 @@
+#include "types.idl"
+
+module forb {
+       // Inter-ORB protocol
+       module iop {
+               
+               typedef octet message_type;
+
+               const message_type REQUEST = 0;
+               const message_type REPLY   = 1;
+               const message_type HELLO   = 2;
+
+               struct version {
+                       octet major, minor;
+               };
+
+               typedef octet message_flags;
+
+               const message_flags LITTLE_ENDIAN = 1;
+
+               struct message_header {
+                       version       proto_version;
+                        message_type  message_type;
+                       message_flags flags;
+                       unsigned long message_size;
+               };
+               const long MESSAGE_HEADER_SIZE = 8;
+               
+               struct request_header {
+                       unsigned long request_id;
+                       string iface;
+                       object_key objkey;
+                       short method_index;
+                       server_id source; ///< Server ID of request originator
+               };
+
+               typedef unsigned short reply_flags;
+               const reply_flags FLAG_EXCEPTION = 1;
+               struct reply_header {
+                       unsigned long request_id;
+                       reply_flags flags;
+               };
+               const long REPLY_HEADER_SIZE = 8;
+
+               native address;
+
+//             struct hello_header {
+//                     address source;
+//             };
+       };
+};
diff --git a/iop.c b/iop.c
index 30b5a706bdfcc449dc8fcbf609a650b8e4b6758b..3c71f53f2cad89607592070d43abb2431d08868a 100644 (file)
--- a/iop.c
+++ b/iop.c
@@ -8,7 +8,6 @@
  * 
  */
 #include <forb/iop.h>
-#include <forb/forb-idl.h>
 #include <forb/cdr.h>
 
 /** Version of the protocol */
diff --git a/iop.h b/iop.h
index 7ac47e29bc4be6ec958d3618e1fee51be5b043b1..4de33925697b848f0f2a9cc9019bbcdc9557c447 100644 (file)
--- a/iop.h
+++ b/iop.h
@@ -1,7 +1,7 @@
 #ifndef FORB_IOP_H
 #define FORB_IOP_H
 
-#include <forb/forb-idl.h>
+#include <forb/iop-idl.h>
 #include <forb/cdr.h>
 #include <forb/forb-internal.h>
 #include "proto.h"
diff --git a/proto.c b/proto.c
index c2da5b797434e4ede8a139b3f0627c563c2cfbfa..916a5a9cd6666d114f41b3fb3d1503f6b3efa8f9 100644 (file)
--- a/proto.c
+++ b/proto.c
@@ -1,5 +1,4 @@
 #include <forb/proto.h>
-#include <forb/forb-idl.h>
 #include <forb/forb-internal.h>
 #include <forb/iop.h>
 #include <forb/config.h>
@@ -459,7 +458,7 @@ forb_proto_send_request(forb_request_t *req, CORBA_Environment *env)
                env->major = FORB_EX_INTERNAL;
                return;
        }
-       peer = forb_get_next_hop(forb, req->obj->server);
+       peer = forb_get_next_hop(forb, &req->obj->server);
        if (!peer) {
                env->major = FORB_EX_TRANSIENT;
                return;
@@ -472,6 +471,4 @@ forb_proto_send_request(forb_request_t *req, CORBA_Environment *env)
                forb_request_delete(forb, req);
                env->major = FORB_EX_COMM_FAILURE;
        }
-exception:
-       ;
 }
index b4a277cd65a02120bd5d4d572a2808ad7d3e1055..6fa31d3326b96d175e374502fb48d0049cac26ed 100644 (file)
@@ -1,4 +1,6 @@
-test_PROGRAMS = hello_inproc proto_unix discovery
+SUBDIRS = $(ALL_OMK_SUBDIRS)
+
+test_PROGRAMS = hello_inproc proto_unix discovery 
 CFLAGS += -DTEST
 
 lib_LOADLIBES = forb ulut fosa rt
@@ -20,3 +22,4 @@ include_GEN_HEADERS = hello.h
 proto_unix_SOURCES = proto_unix.c
 
 discovery_SOURCES = discovery.c
+
diff --git a/tests/object_to_string/Makefile b/tests/object_to_string/Makefile
new file mode 100644 (file)
index 0000000..b22a357
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/tests/object_to_string/Makefile.omk b/tests/object_to_string/Makefile.omk
new file mode 100644 (file)
index 0000000..f8ca37d
--- /dev/null
@@ -0,0 +1,8 @@
+test_PROGRAMS = obj2str
+obj2str_SOURCES = obj2str.c
+obj2str_SERVER_IDL = interface.idl
+
+CFLAGS += -I.
+
+
+lib_LOADLIBES = forb ulut fosa rt
diff --git a/tests/object_to_string/interface.idl b/tests/object_to_string/interface.idl
new file mode 100644 (file)
index 0000000..6661304
--- /dev/null
@@ -0,0 +1,3 @@
+interface i {
+       void method();
+};
diff --git a/tests/object_to_string/obj2str.c b/tests/object_to_string/obj2str.c
new file mode 100644 (file)
index 0000000..c441ba2
--- /dev/null
@@ -0,0 +1,23 @@
+#include <forb/forb.h>
+#include <stdio.h>
+#include "interface.h"
+
+struct forb_i_impl i_impl =  { NULL };
+
+int main()
+{
+       forb_object orb, obj;
+       char *str;
+       orb = forb_init();
+
+       obj = forb_i_new(NULL, &i_impl, orb);
+
+       str = forb_object_to_string(obj);
+       if (str) {
+               printf("Object reference: %s\n", str);
+               forb_free(str);
+       } else {
+               return 1;
+       }
+       return 0;
+}
diff --git a/types.idl b/types.idl
new file mode 100644 (file)
index 0000000..3357b60
--- /dev/null
+++ b/types.idl
@@ -0,0 +1,8 @@
+module forb {
+       typedef long long object_key;
+
+       typedef char uuid[8];
+       struct server_id {
+               uuid uuid;
+       };
+};