MateComponentPersistStream

## MateComponentPersistStream MateComponentPersistStream — Interface for anything that can save / load itself from a MateComponent stream. |

## Synopsis

                        MateComponentPersistStream;
                        MateComponentPersistStreamClass;
    void                (*MateComponentPersistStreamIOFn)          (MateComponentPersistStream *ps,
                                                             const MateComponent_Stream stream,
                                                             MateComponent_Persist_ContentType type,
                                                             void *closure,
                                                             CORBA_Environment *ev);
    MateComponent_Persist_ContentTypeList * (*MateComponentPersistStreamTypesFn)
                                                            (MateComponentPersistStream *ps,
                                                             void *closure,
                                                             CORBA_Environment *ev);
    MateComponentPersistStream * matecomponent_persist_stream_new         (MateComponentPersistStreamIOFn load_fn,
                                                             MateComponentPersistStreamIOFn save_fn,
                                                             MateComponentPersistStreamTypesFn types_fn,
                                                             const gchar *iid,
                                                             void *closure);
    MateComponentPersistStream * matecomponent_persist_stream_construct   (MateComponentPersistStream *ps,
                                                             MateComponentPersistStreamIOFn load_fn,
                                                             MateComponentPersistStreamIOFn save_fn,
                                                             MateComponentPersistStreamTypesFn types_fn,
                                                             const gchar *iid,
                                                             void *closure);

## Object Hierarchy

      GObject
       +----MateComponentObject
             +----MateComponentPersist
                   +----MateComponentPersistStream

## Description

The PersistStream interface is the interface to use for all new components that are able to load and save themselves to a stream. It should be associated with any MateComponentEmbeddable for use by the container in creating a compound document.

This interface works by connecting callbacks to the methods, in a somewhat deprecated fashion, it is probably better nowadays to simply sub-class the MateComponentXObject and override the epv methods. Either way, after all the caveats here is an example use:

Example 28. Implementing the PersistStream callbacks

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    static void
    load_from_stream (MateComponentPersistStream        *ps,
                      const MateComponent_Stream         stream,
                      MateComponent_Persist_ContentType  type,
                      void                       *closure,
                      CORBA_Environment          *ev)
    {
        EogImageData *image_data = closure;
        g_warning ("Load content from stream of type '%s'", type);
    }
    static gint
    save_to_stream (MateComponentPersistStream        *ps,
                    const MateComponent_Stream         stream,
                    MateComponent_Persist_ContentType  type,
                    void                       *closure,
                    CORBA_Environment          *ev)
    {
        EogImageData *image_data = closure;
        g_warning ("Save content to stream with type '%s'", type);
    }
    static MateComponent_Persist_ContentTypeList *
    get_supported_types (MateComponentPersistStream *ps,
                         void                *closure,
                         CORBA_Environment   *ev)
    {
        return matecomponent_persist_generate_content_types (
            2, "text/plain", "text/html");
    }

Having implemented the callbacks we then have to register them and aggregate the interface to our object:

Example 29. Aggregating a new PersistStream

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    EogImageData *
    eog_image_data_construct (EogImageData *image_data)
    {
        MateComponentObject        *retval;
        MateComponentPersistStream *ps;
        ps = matecomponent_persist_stream_new (
            load_from_stream, save_to_stream,
            get_supported_types, NULL,
            image_data);
        if (ps == NULL) {
            matecomponent_object_unref (MATECOMPONENT_OBJECT (image_data));
            return NULL;
        }
        matecomponent_object_add_interface (MATECOMPONENT_OBJECT (image_data),
                         MATECOMPONENT_OBJECT (ps));
        return image_data;
    }

## Details

### MateComponentPersistStream

    typedef struct _MateComponentPersistStream MateComponentPersistStream;

### Warning

`MateComponentPersistStream` is deprecated and should not be used in newly-written code.

### MateComponentPersistStreamClass

    typedef struct {
    	MateComponentPersistClass parent_class;

    	POA_MateComponent_PersistStream__epv epv;

    	/* methods */
    	void       (*load)         (MateComponentPersistStream        *ps,
    				    MateComponent_Stream              stream,
    				    MateComponent_Persist_ContentType type,
    				    CORBA_Environment          *ev);
    	void       (*save)         (MateComponentPersistStream        *ps,
    				    MateComponent_Stream              stream,
    				    MateComponent_Persist_ContentType type,
    				    CORBA_Environment          *ev);

    	MateComponent_Persist_ContentTypeList * (*get_content_types) (MateComponentPersistStream *ps,
    							       CORBA_Environment   *ev);
    } MateComponentPersistStreamClass;

### Warning

`MateComponentPersistStreamClass` is deprecated and should not be used in newly-written code.

### MateComponentPersistStreamIOFn ()

    void                (*MateComponentPersistStreamIOFn)          (MateComponentPersistStream *ps,
                                                             const MateComponent_Stream stream,
                                                             MateComponent_Persist_ContentType type,
                                                             void *closure,
                                                             CORBA_Environment *ev);

### Warning

`MateComponentPersistStreamIOFn` is deprecated and should not be used in newly-written code.

`ps` : |
`stream` : |
`type` : |
`closure` : |
`ev` : |

### MateComponentPersistStreamTypesFn ()

    MateComponent_Persist_ContentTypeList * (*MateComponentPersistStreamTypesFn)
                                                            (MateComponentPersistStream *ps,
                                                             void *closure,
                                                             CORBA_Environment *ev);

### Warning

`MateComponentPersistStreamTypesFn` is deprecated and should not be used in newly-written code.

`ps` : |
`closure` : |
`ev` : |
Returns : |

### matecomponent_persist_stream_new ()

    MateComponentPersistStream * matecomponent_persist_stream_new         (MateComponentPersistStreamIOFn load_fn,
                                                             MateComponentPersistStreamIOFn save_fn,
                                                             MateComponentPersistStreamTypesFn types_fn,
                                                             const gchar *iid,
                                                             void *closure);

### Warning

`matecomponent_persist_stream_new` is deprecated and should not be used in newly-written code.

Creates a new MateComponentPersistStream object. The various operations for the object are performed by the provided callback functions, which are passed `closure` when they are invoked. If any callback is `NULL`, the corresponding operation is performed by the class load and save routines.

`load_fn` : | Loading routine
`save_fn` : | Saving routine
`types_fn` : | get_content_types routine
`iid` : | OAF IID of the object this interface is aggregated to
`closure` : | Data passed to IO routines.
Returns : | the newly-created MateComponentPersistStream object.

### matecomponent_persist_stream_construct ()

    MateComponentPersistStream * matecomponent_persist_stream_construct   (MateComponentPersistStream *ps,
                                                             MateComponentPersistStreamIOFn load_fn,
                                                             MateComponentPersistStreamIOFn save_fn,
                                                             MateComponentPersistStreamTypesFn types_fn,
                                                             const gchar *iid,
                                                             void *closure);

### Warning

`matecomponent_persist_stream_construct` is deprecated and should not be used in newly-written code.

Initializes the MateComponentPersistStream object. The load and save operations for the object are performed by the provided `load_fn` and `save_fn` callback functions, which are passed `closure` when they are invoked. If either `load_fn` or `save_fn` is `NULL`, the corresponding operation is performed by the class load and save routines.

`ps` : | A MateComponentPersistStream object
`load_fn` : | Loading routine
`save_fn` : | Saving routine
`types_fn` : | returns the supported types
`iid` : | OAF IID of the object this interface is aggregated to
`closure` : | Data passed to IO routines.
Returns : | The initialized MateComponentPersistStream object.