Statesaving
Detailed Description
The statesaving functionality is provided in order to allow applications a convenient way of storing/retrieving short-term state information, such as GUI state details (e.g. the view to the last open document). The information saved by using it does not survive over device powerdown; other means must be used when more persistent storage is required. The application should load the state information during startup in order to present user with the previous state from the start. No automatic saving is done; it is left as responsibility of the application to decide when it is approriate to (re)save the state information. (perhaps by using the Autosave functionality?)
The new osso_state_read() and osso_state_write() functions take care of state data reading from and writing to to a file. The only limitation is that pointers can not be stored, this includes strings, so these strings should be stored as character arrays. The easiest way to do this is to define a structure e.g.
struct state_data{
gchar string[STRING_LENGTH];
guint32 i;
gchar filename[PATH_MAX];
};
The old deprecated way has a preferred format of saved information is "key=value".
Multiple statefiles for same application are not supported (this also includes different versions of the same application).
Function Documentation
|
This function opens a statefile for reading.
- Deprecated:
- use the more robust osso_state_read() function instead. No new code should use this function.
- Parameters:
-
- Returns:
- the file descriptor of the opened file. On an error -1 is returned.
|
|
This function opens a statefile for writing. If statefile already exists, it will be truncated silently without any warnings.
- Deprecated:
- use the more robust osso_state_write() function instead. No new code should use this function.
- Parameters:
-
- Returns:
- the file descriptor of the opened file. On an error -1 is returned.
|
|
This function reads a state. - Parameters:
-
| osso | The library context as returned by osso_initialize. |
| state | A pointer to an allocated osso_state_t structure. The data should point to a memoryblock that is atleast as large as state_size. |
- Returns:
- OSSO_OK if the state reading was successfull. OSSO_ERROR if the operation failed for some reason. OSSO_STATE_ERROR
#define STRING_LEN 77
int func( void) {
osso_state_t state;
osso_return_t ret;
struct state_data{
int i;
char s[STRING_LEN];
int a;
long double f;
}statedata;
memset(&statedata, 0, sizeof( struct state_data));
state. state_data = &statedata;
state. state_size = sizeof( struct state_data);
ret = osso_state_read(osso, state);
return 1;
}
|
|
This function will write the supplied state to a file. Any existing statefile will be over-written. - Parameters:
-
| osso | The library context as returned by osso_initialize. |
| state | The state to save. |
- Returns:
- OSSO_OK if the opertation succeeds
- OSSO_ERROR if the state could not be saved.
- OSSO_INVALID if any argument is invalid.
|
Generated on Mon May 23 03:17:49 2005 for LibOSSO by
1.3.7