static VALUE switch_run( VALUE self ) { setenv( "CHIBACH_HOME", STR2CSTR( rb_funcall( mTrema, rb_intern( "home" ), 0 ) ), 1 ); VALUE name = rb_funcall( self, rb_intern( "name" ), 0 ); rb_gv_set( "$PROGRAM_NAME", name ); int argc = 6; char **argv = xmalloc( sizeof( char * ) * ( uint32_t ) ( argc + 1 ) ); argv[ 0 ] = STR2CSTR( name ); argv[ 1 ] = ( char * ) ( uintptr_t ) "--name"; argv[ 2 ] = STR2CSTR( name ); argv[ 3 ] = ( char * ) ( uintptr_t ) "--datapath_id"; argv[ 4 ] = STR2CSTR( rb_funcall( rb_iv_get( self, "@dpid" ), rb_intern( "to_hex" ), 0 ) ); argv[ 5 ] = ( char * ) ( uintptr_t ) "--daemonize"; argv[ 6 ] = NULL; init_chibach( &argc, &argv ); xfree( argv ); set_controller_connected_handler( handle_controller_connected, ( void * ) self ); set_hello_handler( handle_hello, ( void * ) self ); set_features_request_handler( handle_features_request, ( void * ) self ); set_set_config_handler( handle_set_config, ( void * ) self ); set_flow_mod_handler( handle_flow_mod, ( void * ) self ); set_echo_request_handler( handle_echo_request, ( void * ) self ); if ( rb_respond_to( self, rb_intern( "start" ) ) == Qtrue ) { rb_funcall( self, rb_intern( "start" ), 0 ); } rb_funcall( self, rb_intern( "start_chibach" ), 0 ); return self; }
int main( int argc, char **argv ) { init_chibach( &argc, &argv ); set_hello_handler( handle_hello, NULL ); set_features_request_handler( handle_features_request, NULL ); set_echo_request_handler( handle_echo_request, NULL ); start_chibach(); stop_chibach(); return 0; }