matecomponent-context

## matecomponent-context matecomponent-context — Extensible runtime service interface |

## Synopsis

    MateComponent_Unknown      matecomponent_context_get                  (const CORBA_char *context_name,
                                                             CORBA_Environment *opt_ev);
    void                matecomponent_context_add                  (const CORBA_char *context_name,
                                                             MateComponent_Unknown context);
    MateComponentObject *      matecomponent_context_running_get          (void);
    void                matecomponent_running_context_auto_exit_unref
                                                            (MateComponentObject *object);

## Description

The matecomponent-context code is designed to provide a way to expose CORBA contexts through a single C interface. This is so that language bindings can get away with wrapping a single function, and yet have access to the whole MateComponent service framework. Two examples of this are the MonikerContext and the RunningContext ( see MateComponent_Context.idl ).

Example 1. Getting and using the moniker context

    1
    2
    3
    4
    5
    6
    7
    8
    MateComponent_MonikerContext context;
    MateComponent_Unknown        object;
    context = matecomponent_context_get ("Activation", NULL);
    if (context == CORBA_OBJECT_NIL)
        g_error (_("Internal error, no activation context"));
    object = MateComponent_MonikerContext_getObject (
        "file:/demo/a.jpeg", "MateComponent/Control", ev);
    ...

The list of contexts is open and may be expanded in the future, currently there are the following:

- Activation - MateComponent/MonikerContext

- Running - MateComponent/RunningContext

The running context is particularly useful for ensuring that server processes exit cleanly when all their objects and derived objects are dead. To do this we can simply do the following:

Example 2. How to get a factory to quit when it is idle

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    static void
    last_unref_exit_cb (gpointer      context,
                MateComponentObject *factory)
    {
            matecomponent_object_unref (factory);
        gtk_main_quit ();
    }
    ...
    int main (int argc, char **argv)
    {
        ...
        matecomponent_running_context_ignore_object (MATECOMPONENT_OBJREF (object));
        gtk_signal_connect (GTK_OBJECT (matecomponent_context_running_get ()),
                    "last_unref", last_unref_exit_cb, factory);
        ...
        matecomponent_main ();
    }

Since this is a commonly used thing there is a helper to make this easier:

Example 3. How to get a factory to quit when it is idle

    1
    matecomponent_running_context_auto_exit_unref (factory)

## Details

### matecomponent_context_get ()

    MateComponent_Unknown      matecomponent_context_get                  (const CORBA_char *context_name,
                                                             CORBA_Environment *opt_ev);

The most useful context is named 'Activation' and returns the IDL:MateComponent/ActivationContext:1.0 interface.

`context_name` : | the name of the context
`opt_ev` : | optional Environment, or NULL
Returns : | a new reference to a global MateComponent context or CORBA_OBJECT_NIL

### matecomponent_context_add ()

    void                matecomponent_context_add                  (const CORBA_char *context_name,
                                                             MateComponent_Unknown context);

This function adds a new context to the context system

`context_name` : | the name to refer to the context by
`context` : | The MateComponent_Unknown; a ref. is taken on this.

### matecomponent_context_running_get ()

    MateComponentObject *      matecomponent_context_running_get          (void);

Returns : |

### matecomponent_running_context_auto_exit_unref ()

    void                matecomponent_running_context_auto_exit_unref
                                                            (MateComponentObject *object);

`object` : |