Пример #1
0
void test_ListenerCmd_CheckIncomingMessages_should_handle_incoming_ADD_SOCKET_command(void) {
    connection_info *ci = calloc(1, sizeof(*ci));
    *(int *)&ci->fd = 91;

    listener_msg msg = {
        .type = MSG_ADD_SOCKET,
        .u.add_socket = {
            .info = ci,
            .notify_fd = 7,
        },
    };

    setup_command(&msg, NULL);
    int res = 1;

    l->tracked_fds = 3;
    for (int i = 0; i < l->tracked_fds; i++) {
        l->fds[i + INCOMING_MSG_PIPE].fd = i;
        l->fds[i + INCOMING_MSG_PIPE].events = POLLIN;
    }

    expect_notify_caller(l, 7);
    ListenerTask_ReleaseMsg_Expect(l, &l->msgs[0]);
    ListenerCmd_CheckIncomingMessages(l, &res);

    TEST_ASSERT_EQUAL(ci, l->fd_info[3]);
    TEST_ASSERT_EQUAL(ci->fd, l->fds[3 + INCOMING_MSG_PIPE].fd);
    TEST_ASSERT_EQUAL(31, ci->to_read_size);
    TEST_ASSERT_EQUAL(POLLIN, l->fds[3 + INCOMING_MSG_PIPE].events);
    TEST_ASSERT_EQUAL(4, l->tracked_fds);
}
Пример #2
0
/** interpret_command(char* line)
**		Take the input from stdin or a script file and react appropriately.
**		This means executing a command, changing the directory or exiting.
*/
void interpret_command(char* line) {
	if (line[0] == '#') { 
		/*Comment - do nothing*/
		return;
	}
	/*Check for pipes*/
	else if (count_char(line, '|') > 0) {
		/*Split the two commands*/
		char** pipeCmds = split_string(line, 1, "|");
		//Make two commands based on [0] and [1] of pipeCmds
		Command cmd1, cmd2;
		//Change last space of pipeCmds to null
		pipeCmds[0][strlen(pipeCmds[0]) - 1] = '\0';
		strcpy(cmd1.cmdString, pipeCmds[0]);
		//Copy from 2nd char, first char is space
		strcpy(cmd2.cmdString, pipeCmds[1] + 1);
		setup_command(&cmd1);
		setup_command(&cmd2);
		//Run the commands
		run_pipe_commands(&cmd1, &cmd2);
	}
	/*Check for in-built command 'exit'*/
	else if (!strcmp(line, "exit") || !strncmp(line, "exit ", 5)) {
		printf("Exiting...\n");
		exit(0);
	}
	/*Check for in-built command 'cd' - no arguments*/
	else if (!strcmp("cd", line) || !strcmp("cd ", line)) {
		chdir(getenv("HOME")); //Change to HOME directory
	}
	//Check for in-built command 'cd' with arguments
	else if (!strncmp("cd ", line, 3)) {
		char* cdDest = split_string(line, count_char(line, ' '), " ")[1];
		chdir(cdDest);
	}
	//Run command normally
	else {
		Command cmd;
		strcpy(cmd.cmdString, line);
		//Set up the command
		setup_command(&cmd);
		run_command(&cmd);
	}
}
Пример #3
0
int main(int argc, char **argv)
{
	int ch, longindex, ret;
	unsigned long flags;
	struct option *long_options;
	const char *short_options;
	char *p;
	struct command commands[] = {
		vdi_command,
		node_command,
		cluster_command,
		debug_command,
		{NULL,}
	};


	if (argc < 3)
		usage(commands, 0);

	flags = setup_command(commands, argv[1], argv[2]);

	optind = 3;

	long_options = build_long_options(command_options);
	short_options = build_short_options(command_options);

	while ((ch = getopt_long(argc, argv, short_options, long_options,
				&longindex)) >= 0) {

		switch (ch) {
		case 'a':
			sdhost = optarg;
			break;
		case 'p':
			sdport = strtol(optarg, &p, 10);
			if (optarg == p || sdport < 1 || sdport > UINT16_MAX) {
				fprintf(stderr, "Invalid port number '%s'\n", optarg);
				exit(EXIT_USAGE);
			}
			break;
		case 'r':
			raw_output = 1;
			break;
		case 'h':
			subcommand_usage(argv[1], argv[2], EXIT_SUCCESS);
			break;
		case '?':
			usage(commands, EXIT_USAGE);
			break;
		default:
			if (command_parser)
				command_parser(ch, optarg);
			else
				usage(commands, EXIT_USAGE);
			break;
		}
	}

	if (!isatty(STDOUT_FILENO) || raw_output)
		highlight = 0;

	if (flags & SUBCMD_FLAG_NEED_NODELIST) {
		ret = update_node_list(SD_MAX_NODES, 0);
		if (ret < 0) {
			fprintf(stderr, "Failed to get node list\n");
			exit(EXIT_SYSFAIL);
		}
	}

	if (flags & SUBCMD_FLAG_NEED_THIRD_ARG && argc == optind)
		subcommand_usage(argv[1], argv[2], EXIT_USAGE);

	return command_fn(argc, argv);
}
void main()
{
    //Local Declarations
    color_t my_color;
    uint16_t speed       = 30;
    my_color.red         = 1;


    spi_bus_init();
    Delay_ms(300);

    while(1)
    {
        receive_data( &buffer, 1 );

        switch( buffer[0] )
        {
            case SETUP_CMD:
                setup_command();
                break;
            case IMAGE_LOAD_CMD:
                image_load_command();
                break;
            case SCROLL_IMG_LEFT_CMD:
                scroll_img_left_command();
                break;
            case SCROLL_IMG_RIGHT_CMD:
                scroll_img_right_command();
                break;
            case WRITE_PXL_CMD:
                write_pxl_command();
                break;
            case WRITE_PXL_IMG_CMD:
                write_pxl_img_command();
                break;
            case ERASE_PXL_CMD:
                erase_pxl_command();
                break;
            case SCROLL_TEXT_LEFT_CMD:
                scroll_text_left_command();
                break;
            case SCROLL_TEXT_RIGHT_CMD:
                scroll_text_right_command();
                break;
            case DISPLAY_SHIFT_UP_CMD:
                display_shift_up_command();
                break;
            case DISPLAY_SHIFT_DOWN_CMD:
                display_shift_down_command();
                break;
            case DISPLAY_SHIFT_RIGHT_CMD:
                display_shift_right_command();
                break;
            case DISPLAY_SHIFT_LEFT_CMD:
                display_shift_left_command();
                break;
            case DISPLAY_SCROLL_OFF_SCRN_UP_CMD:
                display_scroll_off_scrn_up_command();
                break;
            case DISPLAY_SCROLL_OFF_SCRN_DWN_CMD:
                display_scroll_off_scrn_down_command();
                break;
            case DISPLAY_SCROLL_OFF_SCRN_LEFT_CMD:
                display_scroll_off_scrn_left_command();
                break;
            case DISPLAY_SCROLL_OFF_SCRN_RIGHT_CMD:
                display_scroll_off_scrn_right_command();
                break;
            case REFRESH_CMD:
                refresh();
                break;
            case CLR_SCRN_CMD:
                clear_screen_command();
                break;
            default:
                break;
        }
    }
}