summaryrefslogtreecommitdiff
path: root/src/coordinator.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-11-16 17:10:59 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2014-11-16 17:10:59 +0100
commit3ecaed99580f378fbcb2598b2570c65d0f3ebc99 (patch)
tree3b972c7da2a3143727caf901b5ed4fa1f9099521 /src/coordinator.c
parent842308eb541ecf78391addc0b6778f8f1daab1e4 (diff)
downloadbiruda-3ecaed99580f378fbcb2598b2570c65d0f3ebc99.tar.gz
biruda-3ecaed99580f378fbcb2598b2570c65d0f3ebc99.tar.bz2
..
Diffstat (limited to 'src/coordinator.c')
-rw-r--r--src/coordinator.c60
1 files changed, 59 insertions, 1 deletions
diff --git a/src/coordinator.c b/src/coordinator.c
index b88313e..cb462b9 100644
--- a/src/coordinator.c
+++ b/src/coordinator.c
@@ -22,7 +22,10 @@
static pthread_t coordinator_thread;
static int coordinator_sock;
static int coordinator_must_terminate = 0;
-
+
+int nof_workers = 0;
+worker_t worker[MAX_WORKERS];
+
static char *create_discover_answer( )
{
json_object *obj = json_object_new_object( );
@@ -66,7 +69,27 @@ static char *create_discover_answer( )
system_arch( machine_arch, sizeof( machine_arch ) );
json_object *arch = json_object_new_string( machine_arch );
json_object_object_add( obj, "arch", arch );
+
+ json_object *worker_array_obj = json_object_new_array( );
+ for( int i = 0; i < nof_workers; i++ ) {
+ worker_t *w = &worker[i];
+ json_object *worker_obj = json_object_new_object( );
+
+ json_object *name_obj = json_object_new_string( w->name );
+ json_object_object_add( worker_obj, "name", name_obj );
+
+ json_object *mode_obj = json_object_new_string( worker_exection_mode_str( w->mode ) );
+ json_object_object_add( worker_obj, "mode", mode_obj );
+ if( w->mode != WORKER_EXECUTION_DISABLED ) {
+ json_object *command_obj = json_object_new_string( w->command );
+ json_object_object_add( worker_obj, "command", command_obj );
+ }
+
+ json_object_array_add( worker_array_obj, worker_obj );
+ }
+ json_object_object_add( obj, "workers", worker_array_obj );
+
/* produce message as string, caller must free it */
const char *msg = json_object_to_json_string( obj );
char *res = strdup( msg );
@@ -151,6 +174,7 @@ int coordinator_init( const char *control )
int res;
coordinator_must_terminate = 0;
+ nof_workers = 0;
res = pthread_attr_init( &attr );
if( res != 0 ) {
@@ -172,6 +196,16 @@ void coordinator_terminate( )
nn_term( );
}
+static void free_workers( )
+{
+ for( int i = 0; i < nof_workers; i++ ) {
+ worker_t *w = &worker[i];
+
+ free( w->name );
+ free( w->command );
+ }
+}
+
int coordinator_free( )
{
void *result;
@@ -181,6 +215,30 @@ int coordinator_free( )
if( res != 0 ) {
return 1;
}
+
+ free_workers( );
+
+ return 0;
+}
+int coordinator_add_worker( const char *name, worker_execution_mode_t mode, const char *command )
+{
+ if( nof_workers >= MAX_WORKERS ) {
+ fprintf( stderr, "Can't define more workers, limit reached!\n" );
+ return -1;
+ }
+
+ worker_t *w = &worker[nof_workers];
+ w->name = strdup( name );
+ w->mode = mode;
+ if( command != NULL ) {
+ w->command = strdup( command );
+ } else {
+ w->mode = WORKER_EXECUTION_DISABLED;
+ }
+
+ nof_workers++;
+
return 0;
}
+