Esempio n. 1
0
static	int
_StartBatch(
	MessageHandler	*handler,
	char	*name,
	char	*param)
{
	VALUE app_class;
	VALUE app;
	VALUE rc;
	int state;

ENTER_FUNC;
#ifdef	DEBUG
	printf("starting [%s][%s]\n",name,param);
#endif
	RubyConv = NewConvOpt();
	ConvSetSize(RubyConv,ThisBD->textsize,ThisBD->arraysize);
	ConvSetCodeset(RubyConv,ConvCodeset(handler->conv));
	init(handler);

	app_class = load_application(handler->loadpath,name);
	if (NIL_P(app_class)) {
		Warning("%s in not found.",name);
		return -1;
	}
	app = rb_protect_funcall(app_class,rb_intern("new"),&state,0);
	if (state && error_handle(state)) {
		return -1;
	}
	rc = rb_protect_funcall(app, rb_intern("start_batch"), &state,
		1, rb_str_new2(param));
	if (state && error_handle(state))
		Warning("eval start_batch failed");
		return -1;
	if (FIXNUM_P(rc)) {
		return NUM2INT(rc);
	} else {
		return -1;
	}
LEAVE_FUNC;
	return	(rc); 
}
Esempio n. 2
0
void load_bootapp() {
	// Open
	static FIL fil;
	FRESULT res = f_open(&fil, BOOTAPP_PATH, FA_READ);
	if (res == FR_NO_FILE) return; // 'bootapp' doesn't exist, do nothing.
	if (res != FR_OK) {
		syslog(LOG_ERROR, "Open boot application '%s' failed, FRESULT: %d", BOOTAPP_PATH, res);
		return;
	}
	syslog(LOG_NOTICE, "Found boot application '%s', start to load.", BOOTAPP_PATH);

	// Read
	char *ptr_c = (void*)app_binary_buf;
	while (1) {
		UINT br;
		res = f_read(&fil, ptr_c, 1, &br);
		assert(res == FR_OK);
		if (br > 0)
			ptr_c += br;
		else
			break;
	}
	res = f_close(&fil);
	assert(res == FR_OK);


#if 0
	FILE *fin = fopen(filepath, "rb");
	while (fread(ptr_c, 1, 1, fin) > 0)
	ptr_c++;
	fclose(fin);
#endif

	SIZE filesz = ptr_c - (char*) app_binary_buf;
	syslog(LOG_NOTICE, "Loading file completed, file size: %d.", filesz);

	ER ercd = load_application(app_binary_buf, filesz);
	if (ercd != E_OK) {
		syslog(LOG_NOTICE, "Load application failed, ercd: %d.", ercd);
		tslp_tsk(500);
	}
}
Esempio n. 3
0
static	Bool
_ExecuteProcess(
	MessageHandler	*handler,
	ProcessNode	*node)
{
	VALUE app_class;
	VALUE app;
	ValueStruct *dc_module_value;
	char *dc_module;
	int state;
ENTER_FUNC;
	if (handler->loadpath == NULL) {
		Warning("loadpath is required");
		return FALSE;
	}
	dc_module_value = GetItemLongName(node->mcprec->value, "dc.module");
	dc_module = ValueStringPointer(dc_module_value);
	app_class = load_application(handler->loadpath, dc_module);
	if (NIL_P(app_class)) {
		Warning("%s is not found", dc_module);
		return FALSE;
	}
	app = rb_protect_funcall(app_class, rb_intern("new"), &state, 0);
	if (state && error_handle(state)) {
		return FALSE;
	}
	PutApplication(node);
	rb_protect_funcall(app,rb_intern("exec_process"),&state,1,node_info);
	if (state && error_handle(state)) {
		Warning("eval exec_process failed");
		return FALSE;
	}
	GetApplication(node);
	if (ValueInteger(GetItemLongName(node->mcprec->value, "rc")) < 0) {
		return FALSE;
	} else {
		return TRUE;
	}
LEAVE_FUNC;
}
Esempio n. 4
0
void application_config_read_cb(wkr_t* w, scgi_t *scgi){
  LOG_FUNCTION
  char *str;
  /*w->ctl->scgi = scgi_new();
  
  if(w->ctl->scgi == NULL) {
    LOG_ERROR(SEVERE,"Cannot create SCGI Request");
    sigproc();
    return;
  } */ 
  
  if(w->tmp->is_static){

#ifdef W_ZLIB
    str = (char*) scgi_header_value_get(scgi, "LOWER_LIMIT");
    if(str){
      w->tmp->lower_limit = atol(str);
    }

    str = (char*) scgi_header_value_get(scgi, "UPPER_LIMIT");
    if(str){
      w->tmp->upper_limit = atol(str);
    }

#ifdef W_REGEX
    str = (char*) scgi_header_value_get(scgi, "CONTENT_TYPE");
    if(str){
      wr_string_new(w->tmp->r_content_type, str, strlen(str));
    }else {
      wr_string_new(w->tmp->r_content_type, DEFAULT_CONTENT_TYPE, strlen(DEFAULT_CONTENT_TYPE));
    }


    str = (char*) scgi_header_value_get(scgi, "USER_AGENT");
    if(str){
      wr_string_new(w->tmp->r_user_agent, str, strlen(str));
    }
#endif

#endif
  }else{
    if(drop_privileges(w, scgi) == FALSE) {
      wkr_tmp_free(&w->tmp);
      sigproc();
      return;
    }
    
    manipulate_environment_variable(w, scgi);
    str = (char*) scgi_header_value_get(scgi, "PATH");
    if(str){
      wr_string_new(w->tmp->path, str, strlen(str));
    }

    str = (char*) scgi_header_value_get(scgi, "ENV");
    if(str){
      wr_string_new(w->tmp->env, str, strlen(str));
    }

    str = (char*) scgi_header_value_get(scgi, "TYPE");
    if(str){
      wr_string_new(w->tmp->type, str, strlen(str));
    }

    str = (char*) scgi_header_value_get(scgi, "BASE_URI");
    if(str){
      wr_string_new(w->tmp->resolver, str, strlen(str));
    }

    str = (char*) scgi_header_value_get(scgi, "ANALYTICS");
    if(str && strcmp(str,"enabled")==0){
      w->tmp->profiler = 'y';
    }else{
      w->tmp->profiler = 'n'; 
    }
  }
  
  load_application(w);
}
Esempio n. 5
0
static
void test_sd_loader(intptr_t unused) {
#define TMAX_FILE_NUM (100)

	static FILINFO fileinfos[TMAX_FILE_NUM];
	static char    filenames[TMAX_FILE_NUM][_MAX_LFN + 1];
	for (int i = 0; i < TMAX_FILE_NUM; ++i) {
		fileinfos[i].lfname = filenames[i];
		fileinfos[i].lfsize = _MAX_LFN + 1;
	}

	int filenos = 0;

	// Open directory
	static DIR dir;
    FRESULT fres = f_opendir(&dir, SD_APP_FOLDER);
	if (fres != FR_OK) {
		show_message_box("Error", "Open application folder '" SD_APP_FOLDER "' failed.");
//		syslog(LOG_ERROR, "%s(): Open application folder '%s' failed, FRESULT: %d.", __FUNCTION__, SD_APP_FOLDER, fres);
//		tslp_tsk(500);
		return;
	}
//	int dirid = ev3_filesystem_opendir(SD_APP_FOLDER);

	// Read directory
	while (filenos < TMAX_FILE_NUM && f_readdir(&dir, &fileinfos[filenos]) == FR_OK) {
		if (fileinfos[filenos].fname[0] == '\0') // No more file
			break;
		else if (!(fileinfos[filenos].fattrib & AM_DIR)) { // Normal file
			if (fileinfos[filenos].lfname[0] == '\0')
				strcpy(fileinfos[filenos].lfname, fileinfos[filenos].fname);

            // Check extension (hard-coded)
            static const char *non_app_exts[] = { ".rb", ".wav", NULL };
            const char *ext = strrchr(fileinfos[filenos].lfname, '.');
            if (ext != NULL) {
                bool_t not_app = false;
                for (const char **non_app_ext = non_app_exts; *non_app_ext != NULL; non_app_ext++)
                    if (strcasecmp(*non_app_ext, ext) == 0) {
                        not_app = true;
                        break;
                    }
                if (not_app) continue; // ignore this file
            }

			filenos++;
		}
	}
	if (f_closedir(&dir) != FR_OK) {
		show_message_box("Error", "Close application folder '" SD_APP_FOLDER "' failed.");
//		syslog(LOG_ERROR, "%s(): Close application folder '%s' failed.", __FUNCTION__, SD_APP_FOLDER);
//		tslp_tsk(500);
		return;
	}
#if 0
	while (filenos < TMAX_FILE_NUM && ev3_filesystem_readdir(dirid, &fileinfos[filenos]) == E_OK) {
		if (fileinfos[filenos].fname[0] != '\0') {
			filenos++;
		} else break;
	}
	ev3_filesystem_closedir(dirid);
#endif

	static CliMenuEntry entry_tab[TMAX_FILE_NUM + 1];
	for (int i = 0; i < filenos; ++i) {
		entry_tab[i].key = '1' + i;
		entry_tab[i].title = fileinfos[i].lfname;
		entry_tab[i].exinf = i;
	}
	entry_tab[filenos].key = 'Q';
	entry_tab[filenos].title = "Cancel";
	entry_tab[filenos].exinf = -1;

	static CliMenu climenu = {
		.title     = "EV3RT App Loader",
		.msg       = "Select app:",
		.entry_tab = entry_tab,
		.entry_num = sizeof(entry_tab) / sizeof(CliMenuEntry),
	};
	climenu.entry_num = filenos + 1;

	static char filepath[256 * 2];
	while(1) {
		fio_clear_screen();
		show_cli_menu(&climenu);
		const CliMenuEntry* cme = select_menu_entry(&climenu);
		if(cme != NULL) {
			switch(cme->exinf) {
			case -1:
				return;

			default: {
				strcpy(filepath, SD_APP_FOLDER);
				strcat(filepath, "/");
				strcat(filepath, fileinfos[cme->exinf].lfname);

				syslog(LOG_NOTICE, "Start to load the application file '%s'.", filepath);

				// Open
				static FIL fil;
				FRESULT res = f_open(&fil, filepath, FA_READ);
				assert(res == FR_OK);

				// Read
                uint32_t filesz = f_size(&fil);
                if (filesz > TMAX_APP_BINARY_SIZE) {
					show_message_box("Error", "Application is too large.");
                    return;
                }

				UINT br;
				res = f_read(&fil, app_binary_buf, filesz, &br);
                assert(res == FR_OK);
                assert(br == filesz);

				res = f_close(&fil);
				assert(res == FR_OK);

				syslog(LOG_NOTICE, "Loading file completed, file size: %d.", filesz);

				ER ercd = load_application(app_binary_buf, filesz);
				if (ercd == E_OK) {
					load_success = true;
					return;
                } else if (ercd == E_NOSPT) {
					show_message_box("Error", "App ver. before\n"PIL_VERSION_STRING" must be\nrecompiled.");
				} else {
					syslog(LOG_NOTICE, "Load application failed, ercd: %d.", ercd);
					show_message_box("Error", "Failed to load application.");
//					tslp_tsk(500);
				}
			}
			}
		}
	}
}

static
void test_serial_loader(intptr_t portid) {
	ER   ercd;
	SIZE filesz;

	syslog(LOG_NOTICE, "Start to receive an application file using ZMODEM protocol.");
	platform_pause_application(false); // Ensure the priority of Bluetooth  task
	ercd = zmodem_recv_file(portid, app_binary_buf, sizeof(app_binary_buf), &filesz);
	platform_pause_application(true); // Ensure the priority of Bluetooth  task

	if (ercd != E_OK) {
		syslog(LOG_NOTICE, "Receiving file failed, ercd: %d.", ercd);
		show_message_box("Error", "Receiving application file failed.");
//		tslp_tsk(500);
		return;
	}

	syslog(LOG_NOTICE, "Receiving file completed, file size: %d bytes", filesz);
	show_message_box("App Received", "Click the CENTER button to run.");

	ercd = load_application(app_binary_buf, filesz);
	if (ercd == E_OK) {
		load_success = true;
	} else {
		syslog(LOG_NOTICE, "Load application failed, ercd: %d.", ercd);
		show_message_box("Error", "Failed to load application.");
//		tslp_tsk(500);
	}
}