Bonobo API Reference Manual
<<< Previous Page | Home | Up | Next Page >>>

# BonoboObject

## Name

BonoboObject -- Base object for wrapping Bonobo::Unknown derived objects.

## Synopsis

    typedef     BonoboObjectServant;
    typedef     BonoboObject;
    typedef     BonoboObjectClass;
    BonoboObject* bonobo_object_construct       (BonoboObject *object,
                                                 CORBA_Object corba_object);
    BonoboObject* bonobo_object_new_from_servant
                                                (void *servant);
    BonoboObject* bonobo_object_from_servant    (PortableServer_Servant servant);
    void        bonobo_object_bind_to_servant   (BonoboObject *object,
                                                 void *servant);
    PortableServer_Servant bonobo_object_get_servant
                                                (BonoboObject *object);
    POA_Bonobo_Unknown__epv* bonobo_object_get_epv
                                                (void);
    Bonobo_Unknown bonobo_object_activate_servant
                                                (BonoboObject *object,
                                                 void *servant);
    Bonobo_Unknown bonobo_object_activate_servant_full
                                                (BonoboObject *object,
                                                 void *servant,
                                                 gpointer shlib_id);
    void        bonobo_object_add_interface     (BonoboObject *object,
                                                 BonoboObject *newobj);
    BonoboObject* bonobo_object_query_local_interface
                                                (BonoboObject *object,
                                                 const char *repo_id);
    Bonobo_Unknown bonobo_object_query_interface
                                                (BonoboObject *object,
                                                 const char *repo_id);
    Bonobo_Unknown bonobo_object_corba_objref   (BonoboObject *object);
    Bonobo_Unknown bonobo_object_dup_ref        (Bonobo_Unknown object,
                                                 CORBA_Environment *ev);
    void        bonobo_object_release_unref     (Bonobo_Unknown object,
                                                 CORBA_Environment *ev);
    void        bonobo_object_ref               (BonoboObject *object);
    void        bonobo_object_unref             (BonoboObject *object);
    void        bonobo_object_idle_unref        (BonoboObject *object);
    void        bonobo_object_init              (void);
    void        bonobo_object_trace_refs        (BonoboObject *object,
                                                 const char *fn,
                                                 int line,
                                                 gboolean ref);
    void        bonobo_object_dump_interfaces   (BonoboObject *object);
    void        bonobo_object_check_env         (BonoboObject *object,
                                                 CORBA_Object corba_object,
                                                 CORBA_Environment *ev);
    void        bonobo_object_list_unref_all    (GList **list);
    void        bonobo_object_slist_unref_all   (GSList **list);
    #define     BONOBO_OBJREF                   (o)
    #define     BONOBO_OBJECT_CHECK             (o,c,e)
    gboolean    bonobo_unknown_ping             (Bonobo_Unknown object);

## Object Hierarchy

      GtkObject
       +----BonoboObject

## Signal Prototypes

    "query-interface"
                void        user_function      (BonoboObject *bonoboobject,
                                                gpointer arg1,
                                                gpointer arg2,
                                                gpointer user_data);
    "system-exception"
                void        user_function      (BonoboObject *bonoboobject,
                                                gpointer arg1,
                                                gpointer arg2,
                                                gpointer user_data);

## Description

BonoboObject is the base object in Bonobo for wrapping CORBA servers as Gtk+ objects. HOWEVER, since it's use is complicated, it is left in bonobo for the benefit of Nautilus' binary compatibility. It is strongly recommended that BonoboXObject be used for all new CORBA server implementations.

Again if you are looking to implement a CORBA interface you want to see BonoboXObject.

The `Bonobo::Unknown` interface (wrapped by BonoboObject) is the foundation for the component system: it provides life cycle management for objects as well as service discovery.

The Bonobo interfaces are all based on the `Bonobo::Unknown` interface. This interface is very simple and provides two basic services: object lifetime management and object functionality-discovery. This interface only contains three methods, here it is:

      module Bonobo {
          interface Unknown {
              void void ref();
              void void unref();
              Object query_interface (in string repoid);
          };
      };

The `ref()` and `unref()` methods are used to control the lifetime of an object. The `query_interface` method is used to discover optional functionality provided by the object implementation.

The lifetime management is based on reference counting: when a component is initially launched, it starts life with a reference count of one. This reference is held by the component invoker. Each time a reference is kept to this object (say, you store a copy of the object in an array), the reference count is incremented. Every time a reference goes out of scope, the reference count needs to be decremented. When the reference count reaches zero, the component knows that there are no outstanding references to it, and it is safe to shutdown. At this point, the component shuts down.

It is possible to ask an object which implements the `Bonobo::Unknown` interface if it supports other CORBA interfaces. For example, it would be possible to ask an object whether it supports the "IDL:Bonobo/EmbeddablePrint:1.0" interface to find out if it is possible to print its contents. If the return value from invoking the `query_interface` method on the interface is CORBA_OBJECT_NIL, then we know that the requested interface is not supported. Otherwise, we can invoke IDL:Bonobo/EmbeddablePrint:1.0 methods on the returned CORBA Object.

Clients of the `query_interface` method use it to discover dynamically if a component supports a given interface. Sometimes the client code would require a specific interface to exist, but many times it is possible to operate in a "downgraded" mode. You should design your code to be able to cope with the lack of interfaces in objects. This will allow your program to deal with more components, and this also allows components to work in more situations.

For example, a help browser can load an HTML renderer component and ask this component which sort of features are supported by it:

    stop_animations (BrowserHTML html)
    {
      BrowserControl control

      control = html->query_interface ("IDL:Browser/Control:1.0");
      if (control)
              control->stop_animations();
    }

The return value of the query_interface invocation contains a reference to a CORBA object that is derived from the `Bonobo::Unknown` interface or CORBA_OBJECT_NIL if the interface is not supported by the object. And this interface would have been already `ref()`ed before it was returned. It is up to the caller to call `unref()` when they are done using the interface.

BonoboObject implements the Bonobo::Unknown interface and exports the implementations of the methods in this class to simplify creating new objects that inherit from Bonobo::Unknown. This base object provides default implementations for the ref, unref and query_interface methods.

Other implementations reuse this implementation by listing on their VEPV tables the bonobo_object_epv entry point vector.

The `Bonobo::Unknown` interface is inspired by the Microsoft COM `IUnknown` interface but it has been translated into the CORBA world.

## Details

### BonoboObjectServant

    typedef struct {
    	POA_Bonobo_Unknown servant_placeholder;
    	gpointer           bonobo_object;
    } BonoboObjectServant;

This structure defines the type for BonoboObject-based CORBA servants.

BonoboObject provides a mapping from the servant to the BonoboObject by using the bonobo_object field in the structure. Typically in the C CORBA binding, per-servant information is piggy-backed to the POA servant. With the BonoboObject setup per-servant information is typically attached to the BonoboObject (by using the regular inheritance mechanism of Gtk+). Going from a PortableServer_Servant to the actual BonoboObject is accomplished using the bonobo_object_from_servant() routine.

If you decide not to use this scheme for fetching your per-servant information, but still want to inherit from a BonoboObject object, just make sure that the second field of your servant is a gpointer.

### BonoboObject

    typedef struct {
    	GtkObject            base;

    	Bonobo_Unknown       corba_objref;
    	gpointer             servant;
    	BonoboObjectPrivate *priv;
    } BonoboObject;

### BonoboObjectClass

    typedef struct {
    	GtkObjectClass parent_class;

    	/*
    	 * signals.
    	 */
    	void  (*query_interface) (BonoboObject *object, const char *repo_id,  CORBA_Object      *retval);
    	void  (*system_exception)(BonoboObject *object, CORBA_Object cobject, CORBA_Environment *ev);
    	gpointer expansion;
    } BonoboObjectClass;

### bonobo_object_construct ()

    BonoboObject* bonobo_object_construct       (BonoboObject *object,
                                                 CORBA_Object corba_object);

Initializes the provided BonoboObject `object`. This method is usually invoked from the construct method for other Gtk-based CORBA wrappers that derive from the Bonobo::Unknown interface

`object` : | The GTK object server wrapper for the CORBA service.
`corba_object` : | the reference to the real CORBA object.
Returns : | the initialized BonoboObject.

### bonobo_object_new_from_servant ()

    BonoboObject* bonobo_object_new_from_servant
                                                (void *servant);

`servant` : | A Servant that implements the Bonobo::Unknown interface
Returns : | The servant `servant` wrapped in a BonoboObject.

### bonobo_object_from_servant ()

    BonoboObject* bonobo_object_from_servant    (PortableServer_Servant servant);

CORBA method implementations receive a parameter of type PortableServer_Servant which is a pointer to the servant that was used to create this specific CORBA object instance.

This routine allows the user to get the BonoboObject (ie, Gtk object wrapper) from the servant. This BonoboObject is the Gtk object wrapper associated with the CORBA object instance whose method is being invoked.

`servant` : | Your servant.
Returns : | the BonoboObject wrapper associated with `servant`.

### bonobo_object_bind_to_servant ()

    void        bonobo_object_bind_to_servant   (BonoboObject *object,
                                                 void *servant);

This routine binds `object` to `servant`. It establishes a one to one mapping between the `object` and the `servant`. Utility routines are provided to go back and forth. See bonobo_object_from_servant() and bonobo_object_get_servant().

This routine is used internally by bonobo_object_activate_servant().

`object` : | the BonoboObject to bind to the servant.
`servant` : | A PortableServer_Servant to bind to the BonoboObject.

### bonobo_object_get_servant ()

    PortableServer_Servant bonobo_object_get_servant
                                                (BonoboObject *object);

`object` : | A BonoboObject which is associated with a servant.
Returns : | The servant associated with `object`, or `NULL` if no servant is bound to `object`.

### bonobo_object_get_epv ()

    POA_Bonobo_Unknown__epv* bonobo_object_get_epv
                                                (void);

Returns : | the Bonobo Object epv.

### bonobo_object_activate_servant ()

    Bonobo_Unknown bonobo_object_activate_servant
                                                (BonoboObject *object,
                                                 void *servant);

`object` : |
`servant` : |
Returns : |

### bonobo_object_activate_servant_full ()

    Bonobo_Unknown bonobo_object_activate_servant_full
                                                (BonoboObject *object,
                                                 void *servant,
                                                 gpointer shlib_id);

This routine activates the `servant` which is wrapped inside the `object` on the bonobo_poa (which is the default POA).

`object` : | a BonoboObject
`servant` : | The servant to activate.
`shlib_id` : | an address to identify the shared library
Returns : | The CORBA_Object that is wrapped by `object` and whose servant is `servant`. Might return CORBA_OBJECT_NIL on failure.

### bonobo_object_add_interface ()

    void        bonobo_object_add_interface     (BonoboObject *object,
                                                 BonoboObject *newobj);

Adds the interfaces supported by `newobj` to the list of interfaces for `object`. This function adds the interfaces supported by `newobj` to the list of interfaces support by `object`. It should never be used when the object has been exposed to the world. This is a firm part of the contract.

`object` : | The BonoboObject to which an interface is going to be added.
`newobj` : | The BonoboObject containing the new interface to be added.

### bonobo_object_query_local_interface ()

    BonoboObject* bonobo_object_query_local_interface
                                                (BonoboObject *object,
                                                 const char *repo_id);

`object` : | A BonoboObject which is the aggregate of multiple objects.
`repo_id` : | The id of the interface being queried.
Returns : | A BonoboObject for the requested interface.

### bonobo_object_query_interface ()

    Bonobo_Unknown bonobo_object_query_interface
                                                (BonoboObject *object,
                                                 const char *repo_id);

`object` : | A BonoboObject to be queried for a given interface.
`repo_id` : | The name of the interface to be queried.
Returns : | The CORBA interface named `repo_id` for `object`.

### bonobo_object_corba_objref ()

    Bonobo_Unknown bonobo_object_corba_objref   (BonoboObject *object);

`object` : | A BonoboObject whose CORBA object is requested.
Returns : | The CORBA interface object for which `object` is a wrapper.

### bonobo_object_dup_ref ()

    Bonobo_Unknown bonobo_object_dup_ref        (Bonobo_Unknown object,
                                                 CORBA_Environment *ev);

This function returns a duplicated CORBA Object reference; it also bumps the ref count on the object. This is ideal to use in any method returning a Bonobo_Object in a CORBA impl. If object is CORBA_OBJECT_NIL it is returned unaffected.

`object` : | a Bonobo_Unknown corba object
`ev` : | Corba_Environment
Returns : | duplicated & ref'd corba object reference.

### bonobo_object_release_unref ()

    void        bonobo_object_release_unref     (Bonobo_Unknown object,
                                                 CORBA_Environment *ev);

This function releases a CORBA Object reference; it also decrements the ref count on the bonobo object. This is the converse of bonobo_object_dup_ref. We tolerate object == CORBA_OBJECT_NIL silently.

`object` : | a Bonobo_Unknown corba object
`ev` : | Corba_Environment, optional

### bonobo_object_ref ()

    void        bonobo_object_ref               (BonoboObject *object);

Increments the reference count for the aggregate BonoboObject.

`object` : | A BonoboObject you want to ref-count

### bonobo_object_unref ()

    void        bonobo_object_unref             (BonoboObject *object);

Decrements the reference count for the aggregate BonoboObject.

`object` : | A BonoboObject you want to unref.

### bonobo_object_idle_unref ()

    void        bonobo_object_idle_unref        (BonoboObject *object);

`object` : |

### bonobo_object_init ()

    void        bonobo_object_init              (void);

### bonobo_object_trace_refs ()

    void        bonobo_object_trace_refs        (BonoboObject *object,
                                                 const char *fn,
                                                 int line,
                                                 gboolean ref);

`object` : |
`fn` : |
`line` : |
`ref` : |

### bonobo_object_dump_interfaces ()

    void        bonobo_object_dump_interfaces   (BonoboObject *object);

`object` : |

### bonobo_object_check_env ()

    void        bonobo_object_check_env         (BonoboObject *object,
                                                 CORBA_Object corba_object,
                                                 CORBA_Environment *ev);

This routine verifies the `ev` environment for any fatal system exceptions. If a system exception occurs, the object raises a "system_exception" signal. The idea is that GtkObjects which are used to wrap a CORBA interface can use this function to notify the user if a fatal exception has occurred, causing the object to become defunct.

`object` : | The object on which we operate
`corba_object` : |
`ev` : | CORBA Environment to check

### bonobo_object_list_unref_all ()

    void        bonobo_object_list_unref_all    (GList **list);

This routine unrefs all valid objects in the list and then removes them from `list` if they have not already been so removed.

`list` : | A list of BonoboObjects *s

### bonobo_object_slist_unref_all ()

    void        bonobo_object_slist_unref_all   (GSList **list);

`list` : |

### BONOBO_OBJREF()

    #define BONOBO_OBJREF(o)          (bonobo_object_corba_objref(BONOBO_OBJECT(o)))

`o` : |

### BONOBO_OBJECT_CHECK()

    #define     BONOBO_OBJECT_CHECK(o,c,e)

Checks if the exception in `e` needs to be signaled. If so, then the proper exception signal is generated on the BonoboObject object `o` for the CORBA reference `c`.

`o` : |
`c` : |
`e` : |

### bonobo_unknown_ping ()

    gboolean    bonobo_unknown_ping             (Bonobo_Unknown object);

Pings the object `object` using the ref/unref methods from Bonobo::Unknown. You can use this one to see if a remote object has gone away.

`object` : | a CORBA object reference of type Bonobo::Unknown
Returns : | `TRUE` if the Bonobo::Unknown `object` is alive.

## Signals

### The "query-interface" signal

    void        user_function                  (BonoboObject *bonoboobject,
                                                gpointer arg1,
                                                gpointer arg2,
                                                gpointer user_data);

`bonoboobject` : | the object which received the signal.
`arg1` : |
`arg2` : |
`user_data` : | user data set when the signal handler was connected.

### The "system-exception" signal

    void        user_function                  (BonoboObject *bonoboobject,
                                                gpointer arg1,
                                                gpointer arg2,
                                                gpointer user_data);

`bonoboobject` : | the object which received the signal.
`arg1` : |
`arg2` : |
`user_data` : | user data set when the signal handler was connected.

## See Also

GtkObject

<<< Previous Page | Home | Up | Next Page >>>
Core Bonobo | BonoboXObject