src/shepp/PollFunctions.H

Go to the documentation of this file.
00001 /* ${copyright}$ */
00002 /* $Id: PollFunctions.H 581 2006-03-15 18:55:45Z eduardo $ */
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     // poll command processing
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 { //cmd->get_op() == "ack"
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         } //_debug
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__

Generated on Thu Jun 8 17:40:00 2006 for libepp_nicbr by  doxygen 1.4.6