Example #1
0
PROCESS_THREAD(checkpoint_serial_process, ev, data)
{
  static int set_fd = -1;
  static int set_count = -1;

  PROCESS_BEGIN();

  /* Note: 'cp', 'rb', and 'mt' commands are intercepted */
  PROCESS_PAUSE();
  uart1_set_input(serial_input_byte_intercept);

  /* Format Coffee? */
  PRINTF("Formatting Coffee\n");
  cfs_coffee_format();
  PRINTF("Formatting Coffee... done!\n");

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == serial_line_event_message && data != NULL);

    if(strcmp("set", data) == 0) {
      /* TODO Handle set command */
      /* Open file */
      cfs_remove("cp");
      cfs_coffee_reserve("cp", checkpoint_arch_size());
      set_fd = cfs_open("cp", CFS_WRITE);
      set_count = 0;
      if(set_fd < 0) {
        printf("SET:FSBUSY\n");
      } else {
        printf("SET:LINE\n");
      }
    } else if(set_fd >= 0 && strcmp("set:done", data) == 0) {
        cfs_close(set_fd);
        set_fd = -1;
        if(set_count == 9862) {
          printf("SET:DONE\n");
        } else {
          printf("SET:WRONGSIZE\n");
        }
    } else if(set_fd >= 0) {
      /* We are ready for another line */
      printf("SET:LINE\n");
      /* Set command: parse hex data */
      int len = strlen((char*)data);
      if(len > 16 || (len%2)!=0) {
        printf("WARN: bad set data: %s\n", (char*)data);
      } else {
        int i;
        for (i=0; i < len; i+=2) {
          uint8_t b =
            (hex_decode_char(((char*)data)[i]) << 4) +
            (hex_decode_char(((char*)data)[i+1]));

          PRINTF("Parsing set command: writing to CFS: %02x\n", b);
          write_byte(set_fd, b); /* TODO Check return value */
          set_count++;
        }
      }
    } else if(strcmp("", data) == 0 ||
        strcmp("cp", data) == 0 ||
        strcmp("rb", data) == 0 ||
        strcmp("mt", data) == 0) {
      /* ignore commands: handled by interrupt */
    } else if(strcmp("ping", data) == 0) {
      nr_pongs++;
      printf("pong %u\n", nr_pongs);
    } else if(strcmp("get", data) == 0) {
      handle_get_command();
    } else {
      printf("WARN: Unknown command: '%s'\n", (char*)data);
    }
  }

  PROCESS_END();
}
Example #2
0
KineticStatus KineticClient_GetPrevious(KineticSession* const session,
                                        KineticEntry* const entry,
                                        KineticCompletionClosure* closure)
{
    return handle_get_command(CMD_GET_PREVIOUS, session, entry, closure);
}
Example #3
0
KineticStatus KineticClient_GetNext(KineticSession* const session,
                                    KineticEntry* const entry,
                                    KineticCompletionClosure* closure)
{
    return handle_get_command(CMD_GET_NEXT, session, entry, closure);
}
Example #4
0
int
handle_command(char *buffer)
{
	int rc = 1;
	char *op;
	int cmdtype;
	static unsigned long mark;

	if (ExtractArg(buffer, &op, &buffer) < 0)
	{
		return -1;
	}

	cmdtype = type_command(op);

	switch (cmdtype)
	{
		case COMMAND_GET:
			handle_get_command(buffer);
			break;
		case COMMAND_SET:
			handle_set_command(buffer);
			break;
		case COMMAND_RESET:
			handle_reset_command(buffer);
			break;
		case COMMAND_BYE:
			handle_bye_command(buffer);
			rc = 0;
			break;
		case COMMAND_CLI:
			handle_cli_command(buffer);
			break;
		case COMMAND_MEMSTART:
#ifdef _DMALLOC_
		dmalloc_message("starting new log");
		mark = dmalloc_mark();
#elif _DBMALLOC_ 
			if(malloc_chain_check(0)!=0)
			{
				int fd;
                fd = open("/usr/local/nextone/logs/malloc.inuse", O_CREAT|O_RDWR
);
                malloc_dump(fd );
                close(fd);

			}
			orig_size = malloc_inuse(&histid1);
#endif
            break;	
		case COMMAND_MEMSTOP:
#ifdef _DMALLOC_
		dmalloc_log_changed(mark, 1, 0, 1);
		dmalloc_message("end of log");
#elif _DBMALLOC_ 
			current_size = malloc_inuse(&histid2);

            if(current_size != orig_size)
            {
				int fd;

                fd = open("/usr/local/nextone/logs/malloc.inuse", O_CREAT|O_RDWR
);
                malloc_list(fd, histid1, histid2);
                close(fd);
            }
#endif
            break;

		case COMMAND_NONE:
		default:
			break;
	}

	return rc;
}