[imbus commit] r43 - in trunk/imbus: src tests

0 views
Skip to first unread message

codesite...@google.com

unread,
Nov 21, 2007, 10:23:53 AM11/21/07
to imbus...@googlegroups.com
Author: james.su
Date: Wed Nov 21 07:23:11 2007
New Revision: 43

Modified:
trunk/imbus/src/im_connection.c
trunk/imbus/src/im_io_channel.c
trunk/imbus/src/im_io_channel.h
trunk/imbus/src/im_io_unix.c
trunk/imbus/src/im_main_loop.c
trunk/imbus/src/im_main_loop.h
trunk/imbus/src/im_module.c
trunk/imbus/src/im_module.h
trunk/imbus/src/im_object.c
trunk/imbus/src/im_object.h
trunk/imbus/src/im_server.c
trunk/imbus/src/im_server.h
trunk/imbus/src/im_server_unix.c
trunk/imbus/src/im_type.c
trunk/imbus/src/im_type.h
trunk/imbus/src/im_type_internal.h
trunk/imbus/tests/test_byte_stream.c
trunk/imbus/tests/test_text_stream.c

Log:
Added IMInitiallyOwned class. Modified all non-transferable classes to derive
from this class.


Modified: trunk/imbus/src/im_connection.c
==============================================================================
--- trunk/imbus/src/im_connection.c (original)
+++ trunk/imbus/src/im_connection.c Wed Nov 21 07:23:11 2007
@@ -28,7 +28,7 @@
/****************** Declaration of object and class structure ************/
struct _IMConnection
{
- IMObject object;
+ IMInitiallyOwned parent_object;

IMIOChannel *channel;
IMObjectQueue *queue;
@@ -38,7 +38,7 @@

struct _IMConnectionClass
{
- IMObjectClass parent_class;
+ IMInitiallyOwnedClass parent_class;
};

/************* Implementation of internal functions ***************/
@@ -100,7 +100,7 @@
void
__im_type_register_connection ()
{
- static IMTypeInfo im_connection_type_info =
+ static IMTypeInfo im_connection_type_info =
{
sizeof (IMConnectionClass), /**< class_size >**/
__im_connection_class_init, /**< class_init >**/
@@ -111,7 +111,7 @@
__im_connection_finalize, /**< instance_finalize >**/
};

- __im_type_register_builtin_class (IM_TYPE_OBJECT,
+ __im_type_register_builtin_class (IM_TYPE_INITIALLY_OWNED,
IM_TYPE_CONNECTION,
"Connection",
&im_connection_type_info,
@@ -156,7 +156,6 @@
_im_assert (connection);
connection->channel = channel;
im_object_ref (channel);
- im_object_ref (connection);
im_io_channel_set_close_on_unref (channel, TRUE);
return connection;
}

Modified: trunk/imbus/src/im_io_channel.c
==============================================================================
--- trunk/imbus/src/im_io_channel.c (original)
+++ trunk/imbus/src/im_io_channel.c Wed Nov 21 07:23:11 2007
@@ -198,7 +198,7 @@
void
__im_type_register_io_channel ()
{
- static IMTypeInfo im_io_channel_type_info =
+ static IMTypeInfo im_io_channel_type_info =
{
sizeof (IMIOChannelClass), /**< class_size >**/
__im_io_channel_class_init, /**< class_init >**/
@@ -209,7 +209,7 @@
__im_io_channel_finalize, /**< instance_finalize >**/
};

- __im_type_register_builtin_class (IM_TYPE_OBJECT,
+ __im_type_register_builtin_class (IM_TYPE_INITIALLY_OWNED,
IM_TYPE_IO_CHANNEL,
"IOChannel",
&im_io_channel_type_info,

Modified: trunk/imbus/src/im_io_channel.h
==============================================================================
--- trunk/imbus/src/im_io_channel.h (original)
+++ trunk/imbus/src/im_io_channel.h Wed Nov 21 07:23:11 2007
@@ -77,7 +77,7 @@

struct _IMIOChannel
{
- IMObject object;
+ IMInitiallyOwned parent_object;

/* Private data */
IMUInt close_on_unref : 1;
@@ -85,7 +85,7 @@

struct _IMIOChannelClass
{
- IMObjectClass parent_class;
+ IMInitiallyOwnedClass parent_class;

IMBool (*valid) (IMIOChannel *channel);
IMBool (*read) (IMIOChannel *channel,

Modified: trunk/imbus/src/im_io_unix.c
==============================================================================
--- trunk/imbus/src/im_io_unix.c (original)
+++ trunk/imbus/src/im_io_unix.c Wed Nov 21 07:23:11 2007
@@ -748,7 +748,6 @@
channel->close_on_unref = FALSE;

IM_IO_CHANNEL_UNIX(channel)->fd = fd;
- im_object_ref (channel);
return channel;
}

@@ -855,7 +854,6 @@

((IMIOChannelUnix *) channel)->fd = fd;
__im_fd_set_close_on_exec (fd);
- im_object_ref (channel);
return channel;
}


Modified: trunk/imbus/src/im_main_loop.c
==============================================================================
--- trunk/imbus/src/im_main_loop.c (original)
+++ trunk/imbus/src/im_main_loop.c Wed Nov 21 07:23:11 2007
@@ -147,7 +147,7 @@
__im_main_loop_finalize, /**< instance_finalize >**/
};

- __im_type_register_builtin_class (IM_TYPE_OBJECT,
+ __im_type_register_builtin_class (IM_TYPE_INITIALLY_OWNED,
IM_TYPE_MAIN_LOOP,
"MainLoop",
&im_main_loop_type_info,
@@ -162,7 +162,6 @@
im_type_is_a (type, IM_TYPE_MAIN_LOOP), 0);
main_loop = (IMMainLoop *) im_object_new (type);
_im_assert (main_loop);
- im_object_ref (main_loop);
return main_loop;
}


Modified: trunk/imbus/src/im_main_loop.h
==============================================================================
--- trunk/imbus/src/im_main_loop.h (original)
+++ trunk/imbus/src/im_main_loop.h Wed Nov 21 07:23:11 2007
@@ -48,12 +48,12 @@

struct _IMMainLoop
{
- IMObject object;
+ IMInitiallyOwned parent_object;
};

struct _IMMainLoopClass
{
- IMObjectClass parent_class;
+ IMInitiallyOwnedClass parent_class;

IMInt (*add_io_read_watch) (IMMainLoop *loop,
IMIOChannel *channel,

Modified: trunk/imbus/src/im_module.c
==============================================================================
--- trunk/imbus/src/im_module.c (original)
+++ trunk/imbus/src/im_module.c Wed Nov 21 07:23:11 2007
@@ -23,7 +23,7 @@
/****************** Declaration of object and class structure ************/
struct _IMModule
{
- IMObject object;
+ IMInitiallyOwned parent_object;

/* private */
lt_dlhandle handle;
@@ -37,7 +37,7 @@

struct _IMModuleClass
{
- IMObjectClass parent_class;
+ IMInitiallyOwnedClass parent_class;

IMHashTable *opened_modules;
};
@@ -68,7 +68,7 @@
im_hash_table_remove (mcp->opened_modules, mp->init);

if (mp->types) {
- IMSize i;
+ IMSize i;
for (i = 0; i < im_array_size (mp->types); ++i) {
if (!im_type_deregister_class (im_array_index (mp->types,
IMType, i))) {
_im_warn_check_failed ("Type %s which belongs to
module %s can't be deregistered!",
@@ -112,7 +112,7 @@
void
__im_type_register_module ()
{
- static IMTypeInfo im_module_type_info =
+ static IMTypeInfo im_module_type_info =
{
sizeof (IMModuleClass), /**< class_size >**/
__im_module_class_init, /**< class_init >**/
@@ -123,7 +123,7 @@
__im_module_finalize, /**< instance_finalize >**/
};

- __im_type_register_builtin_class (IM_TYPE_OBJECT,
+ __im_type_register_builtin_class (IM_TYPE_INITIALLY_OWNED,
IM_TYPE_MODULE,
"Module",
&im_module_type_info,
@@ -183,8 +183,6 @@
im_type_instance_delete (mp);
return 0;
}
-
- im_object_ref (mp);

return mp;
}

Modified: trunk/imbus/src/im_module.h
==============================================================================
--- trunk/imbus/src/im_module.h (original)
+++ trunk/imbus/src/im_module.h Wed Nov 21 07:23:11 2007
@@ -80,7 +80,7 @@
const IMChar* im_module_file_name (const IMModule *module);

/**
- * @brief Build module path
+ * @brief Build module path
*
* This method will build a module path by directory and module_name.
* TODO: is not implemented

Modified: trunk/imbus/src/im_object.c
==============================================================================
--- trunk/imbus/src/im_object.c (original)
+++ trunk/imbus/src/im_object.c Wed Nov 21 07:23:11 2007
@@ -27,6 +27,8 @@
IMPointer stream);
static void __im_object_class_init (IMPointer klass);

+static void __im_initially_owned_initialize(IMPointer obj);
+
/* ========================== IMObject methods
=========================== */
static void
__im_object_initialize (IMPointer obj)
@@ -40,6 +42,7 @@
p->impl = im_slice_new0 (IMObjectImpl);
_im_assert (p->impl);

+ /* initially floating. */
p->impl->refcount = -1;
im_datalist_init (&p->impl->children);
}
@@ -84,7 +87,7 @@
if (len) {
/* serialize all children */
im_stream_put_uint32 ((IMStream*)stream, len);
- return im_datalist_foreach (&((const IMObject*)obj)->impl->children,
+ return im_datalist_foreach (&((const IMObject*)obj)->impl->children,
__foreach_serialize_children,
stream);
} else {
@@ -169,7 +172,7 @@
void
__im_type_register_object ()
{
- static IMTypeInfo im_object_type_info =
+ static IMTypeInfo im_object_type_info =
{
sizeof (IMObjectClass), /**< class_size >**/
__im_object_class_init, /**< class_init >**/
@@ -187,6 +190,34 @@
FALSE);
}

+/* ===================== register IMInitiallyFloatingClass
==================== */
+static void
+__im_initially_owned_initialize (IMPointer obj)
+{
+ im_object_ref(obj);
+}
+
+void
+__im_type_register_initially_owned ()
+{
+ static IMTypeInfo im_initially_owned_type_info =
+ {
+ sizeof (IMInitiallyOwnedClass), /**< class_size >**/
+ 0, /**< class_init >**/
+ 0, /**< class_finalize >**/
+
+ sizeof (IMInitiallyOwned), /**< instance_size >**/
+ __im_initially_owned_initialize,/**< instance_init >**/
+ 0, /**< instance_finalize >**/
+ };
+
+ __im_type_register_builtin_class (IM_TYPE_OBJECT, /**<
Parent class >**/
+ IM_TYPE_INITIALLY_OWNED, /**<
class type >**/
+ "InitiallyOwned",
+ &im_initially_owned_type_info,
+ FALSE);
+}
+
/* ===================== IMObjectClass related functions
==================== */
const IMObjectClass*
im_object_class_get_parent (IMConstPointer klass)
@@ -199,9 +230,9 @@
im_object_new (IMType type)
{
IMObject *object;
-
+
_im_return_val_if_fail (IM_TYPE_IS_OBJECT(type), 0);
-
+
object = im_type_instance_new (type);

_im_assert (object);
@@ -246,11 +277,25 @@
im_type_instance_delete (object);
}

+IMBool
+im_object_is_floating (IMPointer object)
+{
+ _im_return_val_if_fail (im_object_valid (object), FALSE);
+ return ((IMObject *)object)->impl->refcount == -1;
+}
+
+void
+im_object_force_floating (IMPointer object)
+{
+ _im_return_if_fail (((IMObject *)object)->impl->refcount <= 1);
+ ((IMObject *)object)->impl->refcount = -1;
+}
+
IMPointer
im_object_copy (IMPointer dest, IMConstPointer src)
{
const IMObjectClass *cp;
-
+
_im_return_val_if_fail (im_object_valid (dest), 0);
_im_return_val_if_fail (im_object_valid (src), 0);
_im_return_val_if_fail (im_type_instance_is_a (src,
im_type_instance_get_type (dest)), 0);

Modified: trunk/imbus/src/im_object.h
==============================================================================
--- trunk/imbus/src/im_object.h (original)
+++ trunk/imbus/src/im_object.h Wed Nov 21 07:23:11 2007
@@ -29,12 +29,38 @@
*
* All objects which inherit IM_TYPE_OBJECT should have its own
* object struct which contains IMObject as the first member.
+ *
+ * Newly created IMObject instance will have initial reference count
set to -1,
+ * indicating that this instance is floating and not owned by anyone..
+ */
+
+/** @struct IMInitiallyOwnedClass
+ * @brief The base struct for all classes that derived from
+ * IM_TYPE_INITIALLY_OWNED.
+ *
+ * All classes which inherit IM_TYPE_INITIALLY_OWNED should have its own
+ * object class struct which contains IMInitiallyOwnedClass as the first
+ * member.
+ *
+ * Unlike IMObject, objects of InitiallyOwnedClass are not floating initially.
+ * In another word, their reference count will be set to 1 to indiate that
+ * they are owned by their creators.
+ */
+
+/** @struct IMInitiallyOwned
+ * @brief The base struct for all initially owned object instances.
+ *
+ * All objects which inherit IM_TYPE_INITIALLY_OWNED should have its own
+ * object struct which contains IMInitiallyOwned as the first member.
+ *
+ * Objects that are not transferable (can not be copied or serialized),
+ * shall be derived from IM_TYPE_INITIALLY_OWNED.
*/


IM_BEGIN_DECLS

-/*******************< type macros >****************/
+/*******************< type macros for IMObject >****************/
#define IM_OBJECT(object)
(IM_TYPE_INSTANCE_CHECK_CAST((object), IM_TYPE_OBJECT, IMObject))
#define IM_CONST_OBJECT(object)
(IM_TYPE_INSTANCE_CHECK_CAST_CONST((object), IM_TYPE_OBJECT, IMObject))
#define IM_OBJECT_CLASS(klass) (IM_TYPE_CLASS_CHECK_CAST((klass),
IM_TYPE_OBJECT, IMObjectClass))
@@ -44,8 +70,27 @@

#define IM_TYPE_IS_OBJECT(type) (im_type_is_a((type),IM_TYPE_OBJECT))

+/*******************< type macros for IMInitiallyOwned >****************/
+#define IM_INITIALLY_OWNED(object) \
+ (IM_TYPE_INSTANCE_CHECK_CAST((object), IM_TYPE_INITIALLY_OWNED, IMInitiallyOwned))
+#define IM_CONST_INITIALLY_OWNED(object) \
+ (IM_TYPE_INSTANCE_CHECK_CAST_CONST((object),
IM_TYPE_INITIALLY_OWNED, IMInitiallyOwned))
+#define IM_INITIALLY_OWNED_CLASS(klass) \
+ (IM_TYPE_CLASS_CHECK_CAST((klass), IM_TYPE_INITIALLY_OWNED, IMInitiallyOwnedClass))
+#define IM_IS_INITIALLY_OWNED(object) \
+ (IM_TYPE_INSTANCE_CHECK_TYPE((object),IM_TYPE_INITIALLY_OWNED))
+#define IM_IS_INITIALLY_OWNED_CLASS(klass) \
+ (IM_TYPE_CLASS_CHECK_TYPE((klass),IM_TYPE_INITIALLY_OWNED))
+#define IM_INITIALLY_OWNED_GET_CLASS(object) \
+ (IM_TYPE_INSTANCE_GET_CLASS_CAST((object),IM_TYPE_INITIALLY_OWNED,IMInitiallyOwnedClass))
+
+#define IM_TYPE_IS_INITIALLY_OWNED(type) \
+ (im_type_is_a((type),IM_TYPE_IS_INITIALLY_OWNED))
+
typedef struct _IMObject IMObject;
typedef struct _IMObjectClass IMObjectClass;
+typedef struct _IMObject IMInitiallyOwned;
+typedef struct _IMObjectClass IMInitiallyOwnedClass;
typedef struct _IMObjectImpl IMObjectImpl;

struct _IMObjectClass
@@ -114,6 +159,25 @@
void im_object_unref (IMPointer object);

/**
+ * @brief Check if a specified object is currently floating.
+ *
+ * A floating object is not owned by any other object. The reference
count of
+ * a floating object is -1.
+ * Unreferencing a floating object will destroy it directly.
+ * Referencing a floating object will increase its reference count to
1, to
+ * indicate that it's currently owned by someone.
+ */
+IMBool im_object_is_floating (IMPointer object);
+
+/**
+ * @brief Turn a specified object into floating mode, if it's not floating.
+ *
+ * Only objects with one owner (reference count equals to 1) shall be
+ * turned into floating mode again.
+ */
+void im_object_force_floating (IMPointer object);
+
+/**
* @brief Copy the content of src object to dest object.
*
* The copy function is a virtual function. Each class should implement
@@ -124,7 +188,7 @@
*
* The type of src and dest must be same or at least src is a derived
type of
* dest. Otherwise the copy will fail.
- *
+ *
* @param dest Pointer to dest object.
* @param src Pointer to source object.
* @return dest on success, 0 on fail.

Modified: trunk/imbus/src/im_server.c
==============================================================================
--- trunk/imbus/src/im_server.c (original)
+++ trunk/imbus/src/im_server.c Wed Nov 21 07:23:11 2007
@@ -106,7 +106,7 @@
__im_server_finalize, /**< instance_finalize >**/
};

- __im_type_register_builtin_class (IM_TYPE_OBJECT,
+ __im_type_register_builtin_class (IM_TYPE_INITIALLY_OWNED,
IM_TYPE_SERVER,
"Server",
&im_server_type_info,
@@ -121,7 +121,6 @@
im_type_is_a (type, IM_TYPE_SERVER), 0);
server = (IMServer *) im_object_new (type);
_im_assert (server);
- im_object_ref (server);
return server;
}

@@ -133,7 +132,6 @@
/* TODO: Only support IMServerUnix for now. */
server = (IMServer *) im_object_new (IM_TYPE_SERVER_UNIX);
_im_assert (server);
- im_object_ref (server);
if (!IM_SERVER_GET_CLASS(server)->listen (server, address, error)) {
im_object_unref (server);
server = 0;

Modified: trunk/imbus/src/im_server.h
==============================================================================
--- trunk/imbus/src/im_server.h (original)
+++ trunk/imbus/src/im_server.h Wed Nov 21 07:23:11 2007
@@ -41,12 +41,12 @@

struct _IMServer
{
- IMObject object;
+ IMInitiallyOwned parent_object;
};

struct _IMServerClass
{
- IMObjectClass parent_class;
+ IMInitiallyOwnedClass parent_class;
IMBool (*listen) (IMServer *server,
const IMChar *address,
IMIOError *error);

Modified: trunk/imbus/src/im_server_unix.c
==============================================================================
--- trunk/imbus/src/im_server_unix.c (original)
+++ trunk/imbus/src/im_server_unix.c Wed Nov 21 07:23:11 2007
@@ -261,7 +261,6 @@
IMServerUnix *server_unix;
server_unix = (IMServerUnix *) im_object_new (IM_TYPE_SERVER_UNIX);
_im_assert (server_unix);
- im_object_ref (server_unix);
return server_unix;
}

@@ -272,7 +271,6 @@
_im_return_val_if_fail (address != 0, 0);
server_unix = (IMServerUnix *) im_object_new (IM_TYPE_SERVER_UNIX);
_im_assert (server_unix);
- im_object_ref (server_unix);
if (!__im_server_unix_listen ((IMServer*)server_unix, address,
error)) {
im_object_unref (server_unix);
server_unix = 0;

Modified: trunk/imbus/src/im_type.c
==============================================================================
--- trunk/imbus/src/im_type.c (original)
+++ trunk/imbus/src/im_type.c Wed Nov 21 07:23:11 2007
@@ -358,6 +358,7 @@

/* Register built-in class types */
__im_type_register_object ();
+ __im_type_register_initially_owned();
__im_type_register_value ();
__im_type_register_value_array ();
__im_type_register_object_array ();

Modified: trunk/imbus/src/im_type.h
==============================================================================
--- trunk/imbus/src/im_type.h (original)
+++ trunk/imbus/src/im_type.h Wed Nov 21 07:23:11 2007
@@ -72,6 +72,7 @@
IM_TYPE_LAST_FUNDAMENTAL = IM_TYPE_DOUBLE_ARRAY,

IM_TYPE_OBJECT = 32,
+ IM_TYPE_INITIALLY_OWNED,
IM_TYPE_VALUE,
IM_TYPE_VALUE_ARRAY,
IM_TYPE_OBJECT_ARRAY,

Modified: trunk/imbus/src/im_type_internal.h
==============================================================================
--- trunk/imbus/src/im_type_internal.h (original)
+++ trunk/imbus/src/im_type_internal.h Wed Nov 21 07:23:11 2007
@@ -18,6 +18,7 @@
IMBool instantiatable);

void __im_type_register_object (); /**<
Implemented in im_object.c **/
+void __im_type_register_initially_owned (); /**<
Implemented in im_object.c **/
void __im_type_register_value (); /**<
Implemented in im_value.c **/
void __im_type_register_value_array (); /**<
Implemented in im_value_array.c **/
void __im_type_register_object_array (); /**<
Implemented in im_object_array.c **/

Modified: trunk/imbus/tests/test_byte_stream.c
==============================================================================
--- trunk/imbus/tests/test_byte_stream.c (original)
+++ trunk/imbus/tests/test_byte_stream.c Wed Nov 21 07:23:11 2007
@@ -126,7 +126,7 @@
im_stream_put_int32_array (stream, int32dim, 10);

table = im_lookup_table_new_full (12345,
- IM_LOOKUP_TABLE_VERTICAL,
+ IM_LOOKUP_TABLE_TTBLTR,
IM_LOOKUP_TABLE_SHOW_TITLE|
IM_LOOKUP_TABLE_SHOW_CURSOR|IM_LOOKUP_TABLE_VERTICAL_SHRINKABLE,
4, 4);


Modified: trunk/imbus/tests/test_text_stream.c
==============================================================================
--- trunk/imbus/tests/test_text_stream.c (original)
+++ trunk/imbus/tests/test_text_stream.c Wed Nov 21 07:23:11 2007
@@ -125,7 +125,7 @@
im_stream_put_int32_array (stream, int32dim, 10);

table = im_lookup_table_new_full (12345,
- IM_LOOKUP_TABLE_VERTICAL,
+ IM_LOOKUP_TABLE_TTBLTR,
IM_LOOKUP_TABLE_SHOW_TITLE|
IM_LOOKUP_TABLE_SHOW_CURSOR|IM_LOOKUP_TABLE_VERTICAL_SHRINKABLE,
4, 4);

Reply all
Reply to author
Forward
0 new messages