Ejemplo n.º 1
0
//execute the algorithm and continue the program
void MainWindow::algorithm(){

	try{
        ServerConnection server("http://vanriel.eu/devcare/dummy.php");

        auto v = parsejson(server.httpGet());

		vaste_nodes no;
		no.a = v.second[0];
		no.b = v.second[1];
		no.c = v.second[2];

		out = alg.bereken(no, v.first);

        kamer.setError(false);
	}
	catch(const std::runtime_error e){
		cerr<<"exception: "<<e.what()<<endl;
        kamer.setError(true);
	}


	fillbox();
	fillpic();
}
Ejemplo n.º 2
0
void
watcher(void)
{
	Json *jv, *jtop;
	vlong id;
	char *text, *created_at, *user;
	char *buf;
	int fd, n, i;
	char fname[64];

	buf = malloc(BUFSIZ);
	if(buf == nil)
		sysfatal("malloc: %r");

	for(;;){
		fetch(fname);
		fd = open(fname, OREAD);
		n = readn(fd, buf, BUFSIZ);
		if(n <= 0){
			fprint(2, "read failed.\n");
			sleep(INTERVAL);
			continue;
		}
		/*print("(read %d bytes in %s)\n", n, fname);*/
		buf[n] = 0;

		jtop = parsejson(buf);
		if(jtop == nil){
			fprint(2, "parsejson failed.\n");
			sleep(INTERVAL);
			continue;
		}
		jv = jtop->value[0]; /* FIXME */

		for(i = jv->len - 1; i >= 0; i--){
			id = jint(jlookup(jv->value[i], "id"));
			if(id <= lastid)
				continue;
			text = jstring(jlookup(jv->value[i], "text"));
			created_at = jstring(jlookup(jv->value[i], "created_at"));
			user = jstring(jlookup(jv->value[i], "from_user"));
			print("[%s] %s (%s)\n", user, text, created_at);
			lastid = id;
		}

		jclose(jv);
		close(fd);
		sleep(INTERVAL);
	}
}
Ejemplo n.º 3
0
bool CardReader::selectFile(const char* filename, bool silent/*=false*/) {
  const char *oldP = filename;

  if(!cardOK) return false;

  file.close();

  if (!file.exists("restart.gcode")) {
    file.createContiguous(&workDir, "restart.gcode", 1);
    file.close();
  }

  if (file.open(curDir, filename, O_READ)) {
    if ((oldP = strrchr(filename, '/')) != NULL)
      oldP++;
    else
      oldP = filename;
    if(!silent) {
      ECHO_MT(SERIAL_SD_FILE_OPENED, oldP);
      ECHO_EMV(SERIAL_SD_SIZE, file.fileSize());
    }

    for (int c = 0; c < sizeof(fullName); c++)
  		const_cast<char&>(fullName[c]) = '\0';
    strncpy(fullName, filename, strlen(filename));

    #if ENABLED(JSON_OUTPUT)
      parsejson(file);
    #endif
    sdpos = 0;
    fileSize = file.fileSize();
    ECHO_EM(SERIAL_SD_FILE_SELECTED);
    return true;
  }
  else {
    if(!silent) ECHO_EMT(SERIAL_SD_OPEN_FILE_FAIL, oldP);
    return false;
  }
}