![]() | ![]() | ![]() | Libbonobo Reference Manual | ![]() |
---|
BonoboPersistStream — Interface for anything that can save / load itself from a Bonobo stream.
#define BONOBO_PERSIST_STREAM_TYPE struct BonoboPersistStreamPrivate; struct BonoboPersistStream; void (*BonoboPersistStreamIOFn) (BonoboPersistStream *ps, constBonobo_Stream stream,Bonobo_Persist_ContentType type, void *closure,CORBA_Environment *ev);Bonobo_Persist_ContentTypeList * (*BonoboPersistStreamTypesFn) (BonoboPersistStream *ps, void *closure,CORBA_Environment *ev); typedef BonoboPersistStreamClass; BonoboPersistStream* bonobo_persist_stream_new (BonoboPersistStreamIOFn load_fn, BonoboPersistStreamIOFn save_fn, BonoboPersistStreamTypesFn types_fn, constgchar *iid, void *closure); BonoboPersistStream* bonobo_persist_stream_construct (BonoboPersistStream *ps, BonoboPersistStreamIOFn load_fn, BonoboPersistStreamIOFn save_fn, BonoboPersistStreamTypesFn types_fn, constgchar *iid, void *closure);
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
This interface works by connecting callbacks to the methods, in a somewhat deprecated fashion, it is probably better nowadays to simply sub-class the BonoboXObject and override the epv methods. Either way, after all the caveats here is an example use:
Example 4. Implementing the PersistStream callbacks
static void load_from_stream (BonoboPersistStream *ps, const Bonobo_Stream stream, Bonobo_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 (BonoboPersistStream *ps, const Bonobo_Stream stream, Bonobo_Persist_ContentType type, void *closure, CORBA_Environment *ev) { EogImageData *image_data = closure; g_warning ("Save content to stream with type 's'", type); } static Bonobo_Persist_ContentTypeList * get_supported_types (BonoboPersistStream *ps, void *closure, CORBA_Environment *ev) { return bonobo_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 5. Aggregating a new PersistStream
EogImageData * eog_image_data_construct (EogImageData *image_data) { BonoboObject *retval; BonoboPersistStream *ps; ps = bonobo_persist_stream_new ( load_from_stream, save_to_stream, get_supported_types, NULL, image_data); if (ps == NULL) { bonobo_object_unref (BONOBO_OBJECT (image_data)); return NULL; } bonobo_object_add_interface (BONOBO_OBJECT (image_data), BONOBO_OBJECT (ps)); return image_data; }
#define BONOBO_PERSIST_STREAM_TYPE BONOBO_TYPE_PERSIST_STREAM /* deprecated, you should use BONOBO_TYPE_PERSIST_STREAM */
struct BonoboPersistStream { BonoboPersist persist; gboolean is_dirty; /* * For the sample routines, NULL if we use the * methods from the class */ BonoboPersistStreamIOFn save_fn; BonoboPersistStreamIOFn load_fn; BonoboPersistStreamTypesFn types_fn; void *closure; BonoboPersistStreamPrivate *priv; };
void (*BonoboPersistStreamIOFn) (BonoboPersistStream *ps, constBonobo_Stream stream,Bonobo_Persist_ContentType type, void *closure,CORBA_Environment *ev);
ps : | |
stream : | |
type : | |
closure : | |
ev : |
Bonobo_Persist_ContentTypeList * (*BonoboPersistStreamTypesFn) (BonoboPersistStream *ps, void *closure,CORBA_Environment *ev);
ps : | |
closure : | |
ev : | |
Returns : |
typedef struct { BonoboPersistClass parent_class; POA_Bonobo_PersistStream__epv epv; /* methods */ void (*load) (BonoboPersistStream *ps, Bonobo_Stream stream, Bonobo_Persist_ContentType type, CORBA_Environment *ev); void (*save) (BonoboPersistStream *ps, Bonobo_Stream stream, Bonobo_Persist_ContentType type, CORBA_Environment *ev); Bonobo_Persist_ContentTypeList * (*get_content_types) (BonoboPersistStream *ps, CORBA_Environment *ev); } BonoboPersistStreamClass;
BonoboPersistStream* bonobo_persist_stream_new (BonoboPersistStreamIOFn load_fn, BonoboPersistStreamIOFn save_fn, BonoboPersistStreamTypesFn types_fn, constgchar *iid, void *closure);
Creates a new BonoboPersistStream 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 BonoboPersistStream object. |
BonoboPersistStream* bonobo_persist_stream_construct (BonoboPersistStream *ps, BonoboPersistStreamIOFn load_fn, BonoboPersistStreamIOFn save_fn, BonoboPersistStreamTypesFn types_fn, constgchar *iid, void *closure);
Initializes the BonoboPersistStream 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 BonoboPersistStream 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 BonoboPersistStream object. |
<< BonoboPersistFile | bonobo-persist-client >> |