MateComponentPersistFile

MateComponentPersistFile — Interface for anything that can save / load itself from a file.

Synopsis

struct              MateComponentPersistFile;
int                 (*MateComponentPersistFileIOFn)     (MateComponentPersistFile *pf,
                                                         const CORBA_char *uri,
                                                         CORBA_Environment *ev,
                                                         void *closure);
                    MateComponentPersistFileClass;
MateComponentPersistFile * matecomponent_persist_file_new
                                                        (MateComponentPersistFileIOFn load_fn,
                                                         MateComponentPersistFileIOFn save_fn,
                                                         const gchar *iid,
                                                         void *closure);
MateComponentPersistFile * matecomponent_persist_file_construct
                                                        (MateComponentPersistFile *pf,
                                                         MateComponentPersistFileIOFn load_fn,
                                                         MateComponentPersistFileIOFn save_fn,
                                                         const gchar *iid,
                                                         void *closure);

Object Hierarchy

  GObject
   +----MateComponentObject
         +----MateComponentPersist
               +----MateComponentPersistFile

Description

The PersistFile interface is a useful interface for MateComponentizing legacy applications, however, for new / correct applications it is far preferable to implement the MateComponentPersistStream interface, since this will not only result in a nice clean to your application architecture, but also allow the transparent use of local, remote, and synthetic streams.

This interface works by connecting callbacks to the methods, in a pretty 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 25. Persist file implementation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
static gint
load_from_file (MateComponentPersistFile *pf,
                const CORBA_char  *filename,
		CORBA_Environment *ev,
                void              *closure)
{
	EogImageData *image_data = closure;
	g_warning ("Load from '%s'", filename);
	return 0; /* Return 0 on success */
}
static gint
save_to_file (MateComponentPersistFile *pf,
              const CORBA_char  *filename,
              CORBA_Environment *ev,
              void              *closure)
{
	EogImageData *image_data = closure;
	g_warning ("Save to '%s'", filename);
	return 0; /* Return 0 on success */
}


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

Example 26. Aggregating a new PersistFile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
EogImageData *
eog_image_data_construct (EogImageData *image_data)
{
	MateComponentObject        *retval;
	MateComponentPersistFile   *file;
	file = matecomponent_persist_file_new (
		load_from_file, save_to_file, image_data);
	if (file == NULL) {
		matecomponent_object_unref (MATECOMPONENT_OBJECT (image_data));
		return NULL;
	}
	matecomponent_object_add_interface (MATECOMPONENT_OBJECT (image_data),
				     MATECOMPONENT_OBJECT (file));
	return image_data;
}


Note again, that you should be writing a MateComponentPersistStream interface, however if you have already done this you might like to just have hooks through so that old apps can use the PersistFile interface:

Example 27. Chaining to a PersistStream implementation

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
29
30
31
32
33
34
35
36
static gint
load_from_file (MateComponentPersistFile *pf,
                const CORBA_char  *filename,
		CORBA_Environment *ev,
                void              *closure)
{
	MateComponent_PersistStream ps = closure;
	MateComponentStream *stream;
	stream = matecomponent_stream_open (
		MATECOMPONENT_IO_DRIVER_FS,
		filename, MateComponent_STORAGE_READ,
		0);
	if (!stream)
		return 0;
	.. extract content type from file ...
	MateComponent_PersistStream_load (ps, type, ev);
	return 0; /* Return 0 on success */
}
static gint
save_to_file (MateComponentPersistFile *pf,
              const CORBA_char  *filename,
              CORBA_Environment *ev,
              void              *closure)
{
	MateComponent_PersistStream ps = closure;
	MateComponentStream *stream;
	stream = matecomponent_stream_open (
		MATECOMPONENT_IO_DRIVER_FS,
		filename, MateComponent_STORAGE_WRITE | MateComponent_STORAGE_CREATE,
		S_IRUSR | S_IWUSR | S_IRGRP);
	if (!stream)
		return 0;
	.. work out content type we want to save ...
	MateComponent_PersistStream_save (ps, type, ev);
	return 0; /* Return 0 on success */
}


The mime type data can be extracted from mate-vfs or mate-mime.

Details

struct MateComponentPersistFile

struct MateComponentPersistFile;

Warning

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


MateComponentPersistFileIOFn ()

int                 (*MateComponentPersistFileIOFn)     (MateComponentPersistFile *pf,
                                                         const CORBA_char *uri,
                                                         CORBA_Environment *ev,
                                                         void *closure);

Warning

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


MateComponentPersistFileClass

typedef struct {
	MateComponentPersistClass parent_class;

	POA_MateComponent_PersistFile__epv epv;

	/* methods */
	int   (*load)             (MateComponentPersistFile *ps,
				   const CORBA_char  *uri,
				   CORBA_Environment *ev);

	int   (*save)             (MateComponentPersistFile *ps,
				   const CORBA_char  *uri,
				   CORBA_Environment *ev);

	char *(*get_current_file) (MateComponentPersistFile *ps,
				   CORBA_Environment *ev);
} MateComponentPersistFileClass;

Warning

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


matecomponent_persist_file_new ()

MateComponentPersistFile * matecomponent_persist_file_new
                                                        (MateComponentPersistFileIOFn load_fn,
                                                         MateComponentPersistFileIOFn save_fn,
                                                         const gchar *iid,
                                                         void *closure);

Warning

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

Creates a MateComponentPersistFile object. The load_fn and save_fn parameters might be NULL. If this is the case, the load and save operations are performed by the class load and save methods

load_fn :

Loading routine

save_fn :

Saving routine

iid :

OAF IID of the object this interface is aggregated to

closure :

Data passed to IO routines.

Returns :

the MateComponentPersistFile.

matecomponent_persist_file_construct ()

MateComponentPersistFile * matecomponent_persist_file_construct
                                                        (MateComponentPersistFile *pf,
                                                         MateComponentPersistFileIOFn load_fn,
                                                         MateComponentPersistFileIOFn save_fn,
                                                         const gchar *iid,
                                                         void *closure);

Warning

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

Initializes the MateComponentPersistFile object. The load_fn and save_fn parameters might be NULL. If this is the case, the load and save operations are performed by the class load and save methods

pf :

A MateComponentPersistFile

load_fn :

Loading routine

save_fn :

Saving routine

iid :

OAF IID of the object this interface is aggregated to

closure :

Data passed to IO routines.

Returns :

the MateComponentPersistFile.

See Also

MateComponentPersistStream, MateComponentPersist