Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

modelstorage.h File Reference

ModelStorage interface. More...

#include "stmt/statement.h"

Include dependency graph for modelstorage.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define ID_COUNTER_FILE   ".ic"
#define MODEL_STORAGE_DB   "modelstorage.db"
#define MODEL_STORAGE_LOG   "modelstorage.log"
#define MODEL_STORAGE_MAX_CLIENTS   100
 The max number of simultaneously running clients (model_storage instances).
#define MODEL_STORAGE_MAX_GRULES   100
 The max number of get-rules.
#define MODEL_STORAGE_MAX_READINGS   6000
#define MODEL_STORAGE_MAX_SRULES   100
 The max number of set-rules.
#define MODEL_STORAGE_MAX_TXNS   100
 The max number of transactions that can be run simultaneously.
#define MODEL_STORAGE_MAX_UPDATINGS   400
 The max number of update operations per transaction.
#define MODELSTORAGE_ERR_ENCRYPTED   -2014
#define MODELSTORAGE_ERR_LOCKED   -2011
 The max number of readings per transaction.
#define MODELSTORAGE_ERR_READING   -2015
#define MODELSTORAGE_ERR_UNDECRYPTED   -2016
#define MS_MAX_PATH   1024
#define MS_MAX_URI   1024
#define MS_STORAGE_TYPE   extern

Typedefs

typedef _model_storage ModelStorage
 Model storage state.
typedef _model_storage_env ModelStorageEnv
 Model Storage Environment.
typedef _ms_blob MSBlob
 Model Storage BLOB.
typedef void(* MSNotify )(const Statement *list, void *data)
 Notification callback function.
typedef void( MSProgress )(double percent, char *message, void *data)
 Progress notification for various purposes.
typedef _ms_transaction MSTxn
 Transaction information.

Enumerations

enum  MSOption { MS_OPT_LOGFILE = 1, MS_OPT_IDFILE = 2, MS_OPT_SERVER = 3, MS_OPT_DBFILE = 4 }
 Model storage option codes. More...

Functions

MS_STORAGE_TYPE int model_storage_batch_get (ModelStorage *ms, MSTxn *txn, Statement *mask_list, Statement **result)
MS_STORAGE_TYPE int model_storage_begin_transaction (ModelStorageEnv *env, MSTxn **txn)
 Starts the transaction.
MS_STORAGE_TYPE int model_storage_blob_close (MSBlob *blob)
MS_STORAGE_TYPE int model_storage_blob_open (ModelStorage *ms, Node *n, MSBlob **blob)
 Opens blob.
MS_STORAGE_TYPE int model_storage_blob_read (MSBlob *blob, void *buffer, size_t size, size_t *read)
 reads from blob to buffer
MS_STORAGE_TYPE int model_storage_blob_seek (MSBlob *blob, long offset)
MS_STORAGE_TYPE int model_storage_blob_tell (MSBlob *blob, long *offset)
MS_STORAGE_TYPE int model_storage_blob_truncate (MSBlob *blob, size_t size)
MS_STORAGE_TYPE int model_storage_blob_write (MSBlob *blob, void *buffer, size_t size)
 writes buffer to blob
MS_STORAGE_TYPE int model_storage_commit_transaction (ModelStorage *ms, MSTxn *txn)
 Commits the transaction.
MS_STORAGE_TYPE int model_storage_configure (ModelStorageEnv *env, MSOption opt, void *value)
MS_STORAGE_TYPE void model_storage_dump (ModelStorageEnv *env)
 Dumps the current model storage state into the file specified.
MS_STORAGE_TYPE void model_storage_free (ModelStorage *ms)
 Destroys the model storage instance.
MS_STORAGE_TYPE int model_storage_free_env (ModelStorageEnv *env)
 Clears the model.
MS_STORAGE_TYPE int model_storage_get (ModelStorage *ms, MSTxn *txn, Statement *mask, Statement **result)
 Returs a list of statements matching the given mask.
MS_STORAGE_TYPE const char * model_storage_get_context_key (ModelStorage *ms)
 returns the current context key of the modelstorage
MS_STORAGE_TYPE int model_storage_get_count (ModelStorage *ms, MSTxn *txn, Statement *mask, unsigned long *result_count)
 Estimates possible count of retuned statements matching the given mask.
MS_STORAGE_TYPE ModelStorageEnvmodel_storage_get_env (ModelStorage *ms)
 Retruns ModelStorage Environment.
MS_STORAGE_TYPE const char * model_storage_get_filename (ModelStorageEnv *env)
 Returns filename.
MS_STORAGE_TYPE int model_storage_get_new_id (ModelStorage *ms, Node *idnode)
 Generates a new uniq identifier represented with a Node.
MS_STORAGE_TYPE int model_storage_get_time (ModelStorage *ms, time_t *time)
 Returns the current time slice.
MS_STORAGE_TYPE int model_storage_init_env (const char *filename, ModelStorageEnv **env)
 Performs initialization of common structure.
MS_STORAGE_TYPE int model_storage_init_env_se (const char *filename, int descrypt, const char *passphrase, ModelStorageEnv **env)
 Secure version of model_storage_init_env.
MS_STORAGE_TYPE int model_storage_n4_export (ModelStorage *ms, char *filename, MSProgress cb, void *data)
MS_STORAGE_TYPE int model_storage_n4_import (ModelStorage *ms, char *filename, MSProgress cb, void *data)
MS_STORAGE_TYPE ModelStoragemodel_storage_new (ModelStorageEnv *env)
 Creates and initializes the model storage instance.
MS_STORAGE_TYPE int model_storage_restore (ModelStorageEnv *env)
 Loads the current model storate state from file.
MS_STORAGE_TYPE int model_storage_rollback_transaction (ModelStorage *ms, MSTxn *txn)
 Rolls back the current transaction on model storage.
MS_STORAGE_TYPE void model_storage_save (ModelStorageEnv *env)
 Saves the current state of modelstorage.
MS_STORAGE_TYPE int model_storage_save_as (ModelStorageEnv *env, const char *filename)
MS_STORAGE_TYPE int model_storage_save_se (ModelStorageEnv *env, const char *passphrase)
 Encrypts and saves the file.
MS_STORAGE_TYPE int model_storage_set (ModelStorage *ms, MSTxn *txn, Statement *stmt)
 Sets the statement.
MS_STORAGE_TYPE int model_storage_set_context_key (ModelStorage *ms, const char *context_key)
 sets the current context_key of the model storage.
MS_STORAGE_TYPE int model_storage_set_notify (ModelStorage *ms, MSNotify cb, void *data)
 Sets the notify callback.
MS_STORAGE_TYPE int model_storage_set_time (ModelStorage *ms, time_t time)
 Sets the current time slice.
MS_STORAGE_TYPE int notification_read (ModelStorage *ms, Statement *op)
 Pick notification from the notification list.


Detailed Description

ModelStorage interface.

This is the main file to be included when using modelstorage service as an embedded library.

This is an example of using ModelStorage as embedded library:

 #include "modelstorage.h"
 ModelStorage *ms;
 MSTxn *txn;
 Statement *stmt1, *stmt2, *mask1;
 Statement *result; //list of statements
 int err;
 
 //first, initialize common info

 model_storage_init();
 
 //now, instantiate it
 ms = model_storage_new();

 //then, start a transaction
 if( (err = model_storage_begin_transaction(&txn)) ) goto err;
 if( (err = model_storage_set(ms, txn, stmt1)) ) goto err1;
 stmt2->operation = STATEMENT_OP_UNSET;
 if( (err = model_storage_set(ms, txn, stmt2)) ) goto err2;
 if( (err = model_storage_get(ms, txn, mask1, &result) ) goto err3;
 if( (err = model_storage_commit_transaction(ms, txn)) ) goto err4;
  // do something with result
 // free result
 statement_result_free(&result);

 err4:

 err3:
 err2:
 err1:
 
 err:
    // error case trapping

Define Documentation

#define ID_COUNTER_FILE   ".ic"
 

#define MODEL_STORAGE_DB   "modelstorage.db"
 

#define MODEL_STORAGE_LOG   "modelstorage.log"
 

#define MODEL_STORAGE_MAX_CLIENTS   100
 

The max number of simultaneously running clients (model_storage instances).

#define MODEL_STORAGE_MAX_GRULES   100
 

The max number of get-rules.

#define MODEL_STORAGE_MAX_READINGS   6000
 

#define MODEL_STORAGE_MAX_SRULES   100
 

The max number of set-rules.

#define MODEL_STORAGE_MAX_TXNS   100
 

The max number of transactions that can be run simultaneously.

If the number is exceeded when performing model_storage_begin_transaction(), the error value is returned.

#define MODEL_STORAGE_MAX_UPDATINGS   400
 

The max number of update operations per transaction.

If the number is exceeded when performing set-operation the error is returned.

See also:
model_storage_set(), model_storage_set_nr()

#define MODELSTORAGE_ERR_ENCRYPTED   -2014
 

#define MODELSTORAGE_ERR_LOCKED   -2011
 

The max number of readings per transaction.

If this number is exceeded when performing get-operation the error is returned.

See also:
model_storage_get(), model_storage_get_nr()

#define MODELSTORAGE_ERR_READING   -2015
 

#define MODELSTORAGE_ERR_UNDECRYPTED   -2016
 

#define MS_MAX_PATH   1024
 

#define MS_MAX_URI   1024
 

#define MS_STORAGE_TYPE   extern
 


Typedef Documentation

typedef struct _model_storage ModelStorage
 

Model storage state.

typedef struct _model_storage_env ModelStorageEnv
 

Model Storage Environment.

typedef struct _ms_blob MSBlob
 

Model Storage BLOB.

typedef void(* MSNotify)(const Statement *list, void *data)
 

Notification callback function.

Called by ModelStorage when statements are published. Should not modify its argument or rely on readability after function execution.

typedef void( MSProgress)(double percent, char *message, void *data)
 

Progress notification for various purposes.

typedef struct _ms_transaction MSTxn
 

Transaction information.


Enumeration Type Documentation

enum MSOption
 

Model storage option codes.

Enumerator:
MS_OPT_LOGFILE 
MS_OPT_IDFILE 
MS_OPT_SERVER 
MS_OPT_DBFILE 


Function Documentation

MS_STORAGE_TYPE int model_storage_batch_get ModelStorage ms,
MSTxn txn,
Statement mask_list,
Statement **  result
 

MS_STORAGE_TYPE int model_storage_begin_transaction ModelStorageEnv env,
MSTxn **  txn
 

Starts the transaction.

All transactions are considered to be shared between ModelStorage instances. This function allocates memory for MSTxn structure.

  • txn -- a pointer to the pointer of transaction
    Returns:
    zero on success, error value otherwise

MS_STORAGE_TYPE int model_storage_blob_close MSBlob blob  ) 
 

MS_STORAGE_TYPE int model_storage_blob_open ModelStorage ms,
Node n,
MSBlob **  blob
 

Opens blob.

MS_STORAGE_TYPE int model_storage_blob_read MSBlob blob,
void *  buffer,
size_t  size,
size_t *  read
 

reads from blob to buffer

MS_STORAGE_TYPE int model_storage_blob_seek MSBlob blob,
long  offset
 

MS_STORAGE_TYPE int model_storage_blob_tell MSBlob blob,
long *  offset
 

MS_STORAGE_TYPE int model_storage_blob_truncate MSBlob blob,
size_t  size
 

MS_STORAGE_TYPE int model_storage_blob_write MSBlob blob,
void *  buffer,
size_t  size
 

writes buffer to blob

MS_STORAGE_TYPE int model_storage_commit_transaction ModelStorage ms,
MSTxn txn
 

Commits the transaction.

After committing all other ModelStorage instances are notified with results

MS_STORAGE_TYPE int model_storage_configure ModelStorageEnv env,
MSOption  opt,
void *  value
 

MS_STORAGE_TYPE void model_storage_dump ModelStorageEnv env  ) 
 

Dumps the current model storage state into the file specified.

MS_STORAGE_TYPE void model_storage_free ModelStorage ms  ) 
 

Destroys the model storage instance.

MS_STORAGE_TYPE int model_storage_free_env ModelStorageEnv env  ) 
 

Clears the model.

MS_STORAGE_TYPE int model_storage_get ModelStorage ms,
MSTxn txn,
Statement mask,
Statement **  result
 

Returs a list of statements matching the given mask.

  • ms -- ModelStorage pointer
  • txn -- current transaction
  • mask -- Mask to be matched
  • result -- a pointer to the list of statements
    Returns:
    zero on success, error value otherwise

MS_STORAGE_TYPE const char* model_storage_get_context_key ModelStorage ms  ) 
 

returns the current context key of the modelstorage

MS_STORAGE_TYPE int model_storage_get_count ModelStorage ms,
MSTxn txn,
Statement mask,
unsigned long *  result_count
 

Estimates possible count of retuned statements matching the given mask.

MS_STORAGE_TYPE ModelStorageEnv* model_storage_get_env ModelStorage ms  ) 
 

Retruns ModelStorage Environment.

MS_STORAGE_TYPE const char* model_storage_get_filename ModelStorageEnv env  ) 
 

Returns filename.

MS_STORAGE_TYPE int model_storage_get_new_id ModelStorage ms,
Node idnode
 

Generates a new uniq identifier represented with a Node.

  • ms -- ModelStorage pointer
  • idnode -- an address of the node
Returns:
zero on success, error value otherwise.
Usage example:

 ModelStorage *ms;
 Node newid, c, p, o;
 Statement *s;

 // initializing the id node with preferrable prefix:

 node_init_string(&c, "", "None");
 node_init_string(&p, "", "instance-of");
 node_init_string(&o, "", "class");

 if ( model_storage_get_new_id(ms, &newid) ) goto err;

 s = statement_create(&c, &p, &newid, &o);

 if ( model_storage_set(ms, NULL, s) ) goto err;

Note:
Since version 0.0.9, this function didn't need the idnode preinitialized. It initializes the idnode by itself.

MS_STORAGE_TYPE int model_storage_get_time ModelStorage ms,
time_t *  time
 

Returns the current time slice.

MS_STORAGE_TYPE int model_storage_init_env const char *  filename,
ModelStorageEnv **  env
 

Performs initialization of common structure.

To be called before any work with modelstorage functions.

Returns:
Error value in case of impossibility of environment initialization or zero in case of success.

MS_STORAGE_TYPE int model_storage_init_env_se const char *  filename,
int  descrypt,
const char *  passphrase,
ModelStorageEnv **  env
 

Secure version of model_storage_init_env.

MS_STORAGE_TYPE int model_storage_n4_export ModelStorage ms,
char *  filename,
MSProgress  cb,
void *  data
 

MS_STORAGE_TYPE int model_storage_n4_import ModelStorage ms,
char *  filename,
MSProgress  cb,
void *  data
 

MS_STORAGE_TYPE ModelStorage* model_storage_new ModelStorageEnv env  ) 
 

Creates and initializes the model storage instance.

Returns:
a pointer to the ModelStorage instance that is to be deleted with model_storage_free() function

MS_STORAGE_TYPE int model_storage_restore ModelStorageEnv env  ) 
 

Loads the current model storate state from file.

If file is good, sets logging to it.

MS_STORAGE_TYPE int model_storage_rollback_transaction ModelStorage ms,
MSTxn txn
 

Rolls back the current transaction on model storage.

  • ms -- a pointer to the ModelStorage instances
  • txn -- the transaction to be rolled back
    Returns:
    zero value on success, error value otherwise

MS_STORAGE_TYPE void model_storage_save ModelStorageEnv env  ) 
 

Saves the current state of modelstorage.

MS_STORAGE_TYPE int model_storage_save_as ModelStorageEnv env,
const char *  filename
 

MS_STORAGE_TYPE int model_storage_save_se ModelStorageEnv env,
const char *  passphrase
 

Encrypts and saves the file.

MS_STORAGE_TYPE int model_storage_set ModelStorage ms,
MSTxn txn,
Statement stmt
 

Sets the statement.

Performs all necessary s-rules invocations.

  • txn the current transaction, may be NULL -- in this case the transaction will be created and committed automatically.
  • stmt the statment to be set or unset depending on its Statement::operation field.
Returns:
zero if the set-operation was performed successfully and error value otherwise.

MS_STORAGE_TYPE int model_storage_set_context_key ModelStorage ms,
const char *  context_key
 

sets the current context_key of the model storage.

commonly, the context_key is reffered to as user login name

MS_STORAGE_TYPE int model_storage_set_notify ModelStorage ms,
MSNotify  cb,
void *  data
 

Sets the notify callback.

MS_STORAGE_TYPE int model_storage_set_time ModelStorage ms,
time_t  time
 

Sets the current time slice.

MS_STORAGE_TYPE int notification_read ModelStorage ms,
Statement op
 

Pick notification from the notification list.

Picks up the notification and sets the context_key and op correspondent to the fist notification in the list.

  • ms ModelStorage instance
  • context_key -- address where notificating model storage context is to be placed
  • op -- address where to place the opreration notified.
Returns:
zero if the notification list is not empty and error value if the list is empty.
Note:
the op got must be freed with operation_free().
 MoldeStorage *ms;
 const char *ckey;
 Statement op;

 while ( !notification_read(ms, &ckey, &op ) ) {
    // do smth. with op
    
 }


Generated on Wed Dec 27 16:52:21 2006 for VRB Online Server by  doxygen 1.4.4