static jint setRoutes(JNIEnv *env, jobject thiz, jstring jName,
        jstring jRoutes)
{
    const char *name = NULL;
    const char *routes = NULL;
    int count = -1;

    name = jName ? env->GetStringUTFChars(jName, NULL) : NULL;
    if (!name) {
        jniThrowNullPointerException(env, "name");
        goto error;
    }
    routes = jRoutes ? env->GetStringUTFChars(jRoutes, NULL) : NULL;
    if (!routes) {
        jniThrowNullPointerException(env, "routes");
        goto error;
    }
    count = set_routes(name, routes);
    if (count < 0) {
        throwException(env, count, "Cannot set route");
        count = -1;
    }

error:
    if (name) {
        env->ReleaseStringUTFChars(jName, name);
    }
    if (routes) {
        env->ReleaseStringUTFChars(jRoutes, routes);
    }
    return count;
}
Exemplo n.º 2
0
void patchbay_toggled(GtkWidget *togglebutton, gpointer data)
{
	int stream = (long)data >> 16;
	int what = (long)data & 0xffff;

	if (is_active(togglebutton))
		set_routes(stream, what);
}
Exemplo n.º 3
0
void taskB(void)
{
	struct net_context *ctx;

	ctx = get_context(&loopback_addr, DEST_PORT, &any_addr, SRC_PORT);
	if (!ctx) {
		PRINT("%s: Cannot get network context\n", __func__);
		return;
	}

	set_routes();

	send(__func__, TASKBSEM, TASKASEM, ctx);
}
Exemplo n.º 4
0
void main(void)
{
	PRINT("%s: run test_15_4\n", __func__);

	net_init();
	init_test();

	set_routes();

	task_fiber_start(&fiberStack_receiving[0], STACKSIZE,
			 (nano_fiber_entry_t) fiber_receiving, 0, 0, 7, 0);

	task_fiber_start(&fiberStack_sending[0], STACKSIZE,
			 (nano_fiber_entry_t) fiber_sending, 0, 0, 7, 0);
}
Exemplo n.º 5
0
void parse_routes(const char *data) {
    APP_LOG(APP_LOG_LEVEL_DEBUG,"Route data %s",data);

  // Make our own copy of the data
  char *p = malloc(strlen(data));
  
  strncpy(p, data, strlen(data));
  APP_LOG(APP_LOG_LEVEL_DEBUG,"Route data %s",p);

  // Get number of routes in the data
  int nroutes = atoi(get_token(&p,'|'));
  
  if(routes) free(routes);
  routes = malloc(sizeof(route_t)*nroutes);
  
  APP_LOG(APP_LOG_LEVEL_DEBUG,"nroutes %d",nroutes);
  
  // Loop over each route and build appropriate menu items
  for(int i=0; i < nroutes; i++) {
    APP_LOG(APP_LOG_LEVEL_DEBUG,"handling route %d",i);
    routes[i].duration = atoi(get_token(&p,'|'));

    int nlegs = atoi(get_token(&p,'|'));
    routes[i].legs = malloc(sizeof(leg_t)*nlegs);
    
    routes[i].walk = 0;
    routes[i].nlegs = nlegs;
    strcpy(routes[i].transports_str,"");
    APP_LOG(APP_LOG_LEVEL_DEBUG,"trans_str is %s",routes[i].transports_str);
    int first_nonwalk = true;
    for(int j=0; j < nlegs; j++) {
      char* type = get_token(&p,'|');
      
      routes[i].legs[j].length = atoi(get_token(&p,'|'));
      routes[i].legs[j].duration = atoi(get_token(&p,'|'));
      routes[i].legs[j].deptime = atoul(get_token(&p,'|'));

      if(strcmp(type, "walk") == 0) {
        routes[i].walk += routes[i].legs[j].length;
        routes[i].legs[j].type = TYPE_WALK;
      }
      else {
        strncpy(routes[i].legs[j].code, type, 6);
        if(!first_nonwalk) strcat(routes[i].transports_str,", "); // Don't put a comma at the start
        first_nonwalk = false;
        strcat(routes[i].transports_str, routes[i].legs[j].code);
        
        routes[i].legs[j].type = TYPE_BUS;
        
        APP_LOG(APP_LOG_LEVEL_DEBUG, "transports[%d] is now %s (%s)",j,routes[i].legs[j].code,routes[i].transports_str);
      }
      char dist[8];
      nice_dist(routes[i].walk,dist,8);
      
      
      snprintf(routes[i].info_str,32,"%dmin, walk %s",routes[i].duration/60,dist);
      
    }
  }
  
  set_routes(nroutes,routes);
  update_routes_menu();
}