DataSource for C SDK
7.0.2.308582
|
Data Structures | |
struct | ds_init_t |
Defines the DataSource initialisation object. More... | |
Macros | |
#define | DS_INITIALISER |
Default initialiser for the ds_init_t object. More... | |
Typedefs | |
typedef void(* | recv_discard_t) (int peer, int count, char **subjects, unsigned short flags) |
Definition of the function type used for handling data discard requests. More... | |
typedef void(* | recv_map_t) (int peer, char *from, char *to) |
Definition of the function type used for handling map messages. More... | |
typedef void(* | recv_nodata_t) (int peer, char *subject, unsigned short flags) |
Definition of the function type used for receiving "nodata" messages. More... | |
typedef void(* | recv_object_status_t) (int peer, char *subject, int status, unsigned short code, char *msgstr) |
Definition of the function type used for handling objectstatus messages. More... | |
typedef void(* | recv_peer_status_t) (int peer, int status, int val, void *data) |
Definition of the function type used for receiving peer status messages. More... | |
typedef void(* | recv_replay_t) (int peer, ds_data_t *pkt, time_t tm) |
Definition of the function type used for receiving updates from a the DataSource library when calling the various replay functions. More... | |
typedef void(* | recv_request_t) (int peer, int count, char **subjects, unsigned short flags) |
Definition of the function type used for handling data requests. More... | |
typedef void(* | recv_service_status_t) (char *service, int status) |
Definition of the function type used for handling service status messages. More... | |
typedef void(* | recv_update_t) (int peer, ds_data_t *pkt) |
Definition of the function type used for receiving updates from a DataSource peer. More... | |
Functions | |
void | ds_config_init (const char *file, int argc, char **argv) |
Set up the configuration of the DataSource. More... | |
int | ds_init (ds_init_t *init, int argc, char **argv) |
Parse the configuration files and initialise the DataSource library. More... | |
The initialisation of a DataSource process is fairly simple. It comprises of setting up configuration, application settings and entering the event loop.
Configuration options can be added, in the application, but even if they are not the DataSource library will add options that need to be parsed. Calling ds_config_init() will parse the given file and the command line arguments passed in.
The next step is to setup and initialise the application settings. This is done by setting the various members of the ds_init_t structure. Defaults for this can be used by initialising the object to the static initialiser DS_INITIALISER as seen in the example. However, some members will need to be set if the application is to do anything useful. For example the application name and callback functions. This object is then passed to the ds_init() function, which also takes the command line arguments, returning any unparsed arguments.
The last step is to call ds_loop() which enters the application into the event loop. If the DataSource needs to make any connections to external applications other than DataSources, adding a timed event before calling ds_loop() is the normal method. The event callback will then be called after ds_loop() has started.
If the DataSource is multi-threaded and wishes to use the DataSource event manager for the extra threads, those threads must call ds_thread_init() before calling ds_loop(). The main thread only needs to call ds_loop() however.
Example: Sample initialisation code.
Any callbacks specified in the initialiser may potentially be called on multiple threads, sometimes concurrently, as a result it is important that the application is thread-safe.
#define DS_INITIALISER |
Default initialiser for the ds_init_t object.
typedef void(* recv_discard_t) (int peer, int count, char **subjects, unsigned short flags) |
Definition of the function type used for handling data discard requests.
peer | The number of the DataSource peer |
count | Number of objects in this request |
subjects | Array of the object names in this request |
flags | Flags pertaining to this request |
This datatype will only be used when the DataSource is active.
add-peer
entries in the configuration file. The first add-peer
is for peer 0, the next peer 1 and so on. typedef void(* recv_map_t) (int peer, char *from, char *to) |
Definition of the function type used for handling map messages.
from | The subject requested |
to | The subject that from is mapped to |
typedef void(* recv_nodata_t) (int peer, char *subject, unsigned short flags) |
Definition of the function type used for receiving "nodata" messages.
peer | The number of the DataSource peer |
subject | Name of the object this message is being sent for |
flags | The nodata message type |
A "nodata" message tells you of a failure or exception condition, usually in response to requesting an object (for example an "object not found" message).
add-peer
entries in the configuration file. The first add-peer
is for peer 0, the next peer 1 and so on. typedef void(* recv_object_status_t) (int peer, char *subject, int status, unsigned short code, char *msgstr) |
Definition of the function type used for handling objectstatus messages.
peer | The number of the DataSource peer |
subject | Name of the object referred to in this status message |
status | Indicates the type of the status message |
code | User-definable status code |
msgstr | User-definable status message |
add-peer
entries in the configuration file. The first add-peer
is for peer 0, the next peer 1 and so on.The status parameter takes the values OBJ_STATUS_OK, OBJ_STATUS_STALE or OBJ_STATUS_LIMITED.
typedef void(* recv_peer_status_t) (int peer, int status, int val, void *data) |
Definition of the function type used for receiving peer status messages.
peer | The number of the DataSource peer |
status | Status type |
val | Peer ID |
data | Peer name |
This callback will receive messages notifying the application of when the DataSource libraries have made a connection or disconnected with another DataSource peer.
msg Will have the values DS_MSG_CONNECT or DS_MSG_DISCONNECT
add-peer
entries in the configuration file. The first add-peer
is for peer 0, the next peer 1 and so on. typedef void(* recv_replay_t) (int peer, ds_data_t *pkt, time_t tm) |
Definition of the function type used for receiving updates from a the DataSource library when calling the various replay functions.
peer | The number of the DataSource peer |
pkt | The update packet containing the new data |
tm | The time at which the update was originally sent |
add-peer
entries in the configuration file. The first add-peer
is for peer 0, the next peer 1 and so on. typedef void(* recv_request_t) (int peer, int count, char **subjects, unsigned short flags) |
Definition of the function type used for handling data requests.
peer | The number of the DataSource peer |
count | Number of objects in this request |
subjects | Array of the object names in this request |
flags | Flags pertaining to this request |
This datatype will only be used when the DataSource is active.
add-peer
entries in the configuration file. The first add-peer
is for peer 0, the next peer 1 and so on. typedef void(* recv_service_status_t) (char *service, int status) |
Definition of the function type used for handling service status messages.
service | The name of the service |
status | The status type |
typedef void(* recv_update_t) (int peer, ds_data_t *pkt) |
Definition of the function type used for receiving updates from a DataSource peer.
peer | The number of the DataSource peer |
pkt | The update packet containing the new data |
add-peer
entries in the configuration file. The first add-peer
is for peer 0, the next peer 1 and so on. void ds_config_init | ( | const char * | file, |
int | argc, | ||
char ** | argv | ||
) |
Set up the configuration of the DataSource.
file | Filename of the main configuration file |
argc | Number of arguments (as passed to main()) |
argv | Argument array (as passed to main()) |
If file is NULL then the default of "datasrc.conf" is taken.
This should be the first DataSource function that is called by your application. It sets up the configuration of the DataSource.
The command line arguments passed in here will not be altered by this function.
int ds_init | ( | ds_init_t * | init, |
int | argc, | ||
char ** | argv | ||
) |
Parse the configuration files and initialise the DataSource library.
init | The initialisation object |
argc | Number of arguments (as passed to main()) |
argv | Argument array (as passed to main()) |
This function should be called after any local configuration options have been added to the configuration context and the initialisation object has been setup
The command line arguments passed to the application's main() function should also be passed in here. The library will filter out any arguments used by the configuration subsystem and leave only non-matching arguments