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(vector<string> &args)
00045 {
00046 Poll act;
00047 PollCmd *cmd = act.get_command();
00048
00049
00050 if (!args.empty() && !(args[0] == "help")) {
00051 if (args[0] == "req" || args[0] == "ack") {
00052 cmd->set_op(args[0]);
00053 args.erase(args.begin());
00054
00055 if (cmd->get_op() == "req") {
00056 if (!args.empty()) {
00057 return cmd_poll_help("too many arguments");
00058 }
00059 } else {
00060 if (args.empty()) {
00061 return cmd_poll_help("unspecified msgID");
00062 } else if (args.size() > 1) {
00063 return cmd_poll_help("too many arguments");
00064 }
00065 cmd->set_msgID(args[0]);
00066 }
00067
00068 if (_debug) {
00069 printf("poll op: [%s]\n", cmd->get_op().c_str());
00070
00071 if (cmd->get_msgID() != "") {
00072 printf(" msgID: [%s]\n", cmd->get_msgID().c_str());
00073 }
00074 }
00075
00076 if (process_action(act) != 0) {
00077 return -1;
00078 }
00079
00080 return 0;
00081 } else {
00082 return cmd_poll_help("invalid command: poll " + args[0]);
00083 }
00084 }
00085
00086 return cmd_poll_help("");
00087 }
00088
00089 #endif //__POLL_FUNCTIONS_H__