1 #include "osrf_system.h"
3 transport_client* __osrfGlobalTransportClient;
5 transport_client* osrf_system_get_transport_client() {
6 return __osrfGlobalTransportClient;
9 int osrf_system_bootstrap_client( char* config_file, char* contextnode ) {
10 return osrf_system_bootstrap_client_resc(config_file, contextnode, NULL);
13 int osrf_system_bootstrap_client_resc( char* config_file, char* contextnode, char* resource ) {
15 if( !( config_file && contextnode ) && ! osrfConfigHasDefaultConfig() )
16 fatal_handler("No Config File Specified\n" );
20 osrfConfig* cfg = osrfConfigInit( config_file, contextnode );
21 osrfConfigSetDefaultConfig(cfg);
25 char* log_file = osrfConfigGetValue( NULL, "/logfile");
26 char* log_level = osrfConfigGetValue( NULL, "/loglevel" );
27 osrfStringArray* arr = osrfNewStringArray(8);
28 osrfConfigGetValueList(NULL, arr, "/domains/domain");
29 char* username = osrfConfigGetValue( NULL, "/username" );
30 char* password = osrfConfigGetValue( NULL, "/passwd" );
31 char* port = osrfConfigGetValue( NULL, "/port" );
32 char* unixpath = osrfConfigGetValue( NULL, "/unixpath" );
34 char* domain = osrfStringArrayGetString( arr, 0 ); /* just the first for now */
35 osrfStringArrayFree(arr);
40 if(port) iport = atoi(port);
41 if(log_level) llevel = atoi(log_level);
43 log_init( llevel, log_file );
45 info_handler("Bootstrapping system with domain %s, port %d, and unixpath %s", domain, iport, unixpath );
47 transport_client* client = client_init( domain, iport, unixpath, 0 );
49 char* host = getenv("HOSTNAME");
51 if(!resource) resource = "";
52 int len = strlen(resource) + 256;
55 snprintf(buf, len - 1, "opensrf_%s_%s_%d", resource, host, getpid() );
57 if(client_connect( client, username, password, buf, 10, AUTH_DIGEST )) {
58 /* child nodes will leak the parents client... but we can't free
59 it without disconnecting the parents client :( */
60 __osrfGlobalTransportClient = client;
70 if(__osrfGlobalTransportClient)
76 int osrf_system_disconnect_client() {
77 client_disconnect( __osrfGlobalTransportClient );
78 client_free( __osrfGlobalTransportClient );
79 __osrfGlobalTransportClient = NULL;
83 int osrf_system_shutdown() {
85 osrf_system_disconnect_client();
86 osrf_settings_free_host_config(NULL);