00001
00002
00006 #ifndef __POLL_FUNCTIONS_H__
00007 #define __POLL_FUNCTIONS_H__
00008 #include "SheppCommandFunctions.H"
00009
00010 #include "Poll.H"
00011
00013
00018 int cmd_poll_help(string error_msg)
00019 {
00020 if (error_msg != "") {
00021 printf("error: %s\n", error_msg.c_str());
00022 }
00023
00024 printf("poll command syntax help:\n");
00025 printf("\n");
00026
00027 printf(" req\n");
00028 printf("\n");
00029 printf(" ack <msgID>\n");
00030 printf("\n");
00031
00032 if (error_msg != "") {
00033 return -1;
00034 }
00035
00036 return 0;
00037 }
00038
00040
00044 int cmd_poll(char *arg)
00045 {
00046 Poll act;
00047 PollCmd *cmd = act.get_command();
00048
00049 if (strlen(arg) > 0) {
00050 vector<string> words = SheppStrUtil::parse_line(arg);
00051
00052
00053 if (!words.empty() && !(words[0] == "help")) {
00054 if (words[0] == "req" || words[0] == "ack") {
00055 cmd->set_op(words[0]);
00056 words.erase(words.begin());
00057
00058 if (cmd->get_op() == "req") {
00059 if (!words.empty()) {
00060 return cmd_poll_help("too many arguments");
00061 }
00062 } else {
00063 if (words.empty()) {
00064 return cmd_poll_help("unspecified msgID");
00065 } else if (words.size() > 1) {
00066 return cmd_poll_help("too many arguments");
00067 }
00068 cmd->set_msgID(words[0]);
00069 }
00070
00071 if (_debug) {
00072 printf("poll op: [%s]\n", cmd->get_op().c_str());
00073
00074 if (cmd->get_msgID() != "") {
00075 printf(" msgID: [%s]\n", cmd->get_msgID().c_str());
00076 }
00077 }
00078
00079 if (process_action(act) != 0) {
00080 return -1;
00081 }
00082
00083 return 0;
00084 } else {
00085 return cmd_poll_help("invalid command: poll " + words[0]);
00086 }
00087 }
00088 }
00089
00090 return cmd_poll_help("");
00091 }
00092
00093 #endif //__POLL_FUNCTIONS_H__