示例#1
0
文件: pers_cli.c 项目: sigmond/mpl
static int readlines(void) {
    char *line;
    mpl_list_t *reqMsg = NULL;
    int quit = 0;
    mpl_list_t *tmp;

    completionStrings = calloc(maxStrings, sizeof(char *));

    while((line = linenoise("PERS> ")) != NULL) {
        if (line[0] != '\0') {
            if (strcmp(line,"quit") && strncmp(line, "help ", 5)) {
                char *req;
                int ret = -1;
                req = formatCmdLine(line, "Req");
                reqMsg = mpl_param_list_unpack_param_set(req, PERSONNEL_PARAM_SET_ID);
                if (!reqMsg) {
                    printf("Protocol error\n");
                    ret = -1;
                }
                else if (checkCommand(reqMsg) == 0) {
                    ret = pack_and_send(reqMsg);
                }
                mpl_param_list_destroy(&reqMsg);
                free(req);
                if (ret == 0) {
                    fgets(buf, 1024, fi);
                    printf("%s\n", buf);
                }
            }
            else if (!strncmp(line, "help ", 5)) {
                char *helptext;
                persfile_get_command_help(line, &helptext);
                if (helptext != NULL) {
                    printf("%s", helptext);
                    free(helptext);
                }
                else
                    printf("No help\n");
            }
            else {
                quit = 1;
            }
            linenoiseHistoryAdd(line);
            linenoiseHistorySave("history.txt"); /* Save every new entry */
            free(line);
            while ((tmp = mpl_list_remove(&completionCallstack, NULL)) != NULL) {
                completion_callstack_entry_t *e;
                e = MPL_LIST_CONTAINER(tmp, completion_callstack_entry_t, list_entry);
                free(e);
            }
        }
        if (quit)
            break;
    }
    free(completionStrings);
    return 0;
}
示例#2
0
// Configuring a channel
// Verify the things we need to send
int chan_config(int sd)
{
	struct packet *buf;
	buf = malloc(sizeof(struct packet));
	srand(time(NULL));
 	//uint32_t tag = rand() % 10000;
	uint32_t tag = 1;

	// first send a CHANNELCONFIG
	char *msg = "CHANNELCONFIG";
	int sent = pack_and_send(sd, msg, tag, 0, buf);

	// param keepalive?
	int keepalive;
	msg = " keepalive(120), reconnect";
	sent = pack_and_send(sd, msg, tag, 0, buf); 

	sent = pack_and_send(sd, "", tag, 0, buf);
	
	// assuming this is a unique channel id
	// TODO: gotta determine how this channel id is generated
	// u-[8]-[11]--8000 ????
	msg = "ub8a652a-13743a87f30--8000";
	sent = pack_and_send(sd, msg, tag, 0, buf);
  
	//send FIN packet
	msg = "";
	sent = pack_and_send(sd, msg, tag, (uint32_t) 0x00000002, buf);
	
  	
	char recvbuf[100];

	recv(sd, recvbuf, 20, 0);
	// verify(buf);
	recv(sd, recvbuf, 100, 0);
	
	//receive_data(sd, recvbuf);
	printf("received channel id: %s\n", recvbuf);

	return sent;
}
示例#3
0
// If this command is used, we need to parse
// a config file for the params:
// jobsPerNode
// workerManager
// job / job params?
int submit_job(int sd)
{
	struct packet *buf;
	buf = malloc(sizeof(struct packet));
	srand(time(NULL));
 	uint32_t tag = rand() % 10000;
	
	// first send a CONFIGSERVICE
	char *msg = "CONFIGSERVICE";
	int sent = pack_and_send(sd, msg, tag, 0, buf);

	// param jobsPerNode
	int jobs;
	msg = "jobsPerNode=2";
	sent = pack_and_send(sd, msg, tag, 0, buf);

	// param workerManager
	msg = "workerManager=passive";
	sent = pack_and_send(sd, msg, tag, 0, buf);

	// wait to receive an OK
	char recvbuf[100];
	recv(sd, recvbuf, 20, 0);
	// verify(buf);
	recv(sd, recvbuf, 100, 0);
	if (strcmp(recvbuf, "OK") == 0){
		msg = "SUBMITJOB";
		sent = pack_and_send(sd, msg, tag, 0 buf);
	}

	// ??????????????
	// TODO: SOME LARGE FILE
	// ??????????????

	return sent;
}