fipa_acl  1.4
main.cpp
Go to the documentation of this file.
1 
7 #include <iostream>
8 #include <fstream>
9 #include <string>
10 #include <vector>
11 #include <map>
12 
13 #include <fipa_acl/fipa_acl.h>
14 
15 std::map<std::string, std::string> options;
16 
17 
18 void info(char** argv)
19 {
20  printf("usage: %s -b <binary-message-file> -i \n", argv[0]);
21  printf("-b require a binary message file as input\n");
22  printf("-i interactive mode\n");
23  exit(0);
24 }
25 
26 bool usage(int argc, char** argv)
27 {
28  int option;
29 
30  while( (option = getopt(argc, argv, "hb:i")) != -1 )
31  {
32  switch(option)
33  {
34  case 'b':
35  options["binary-msg-file"] = optarg;
36  break;
37  case 'i':
38  options["interactive"] = "Y";
39  break;
40  case 'h':
41  info(argv);
42  break;
43  default:
44  break;
45  }
46  }
47 
48  return true;
49 }
50 
51 bool parseMsg(const std::string& storage)
52 {
53  using namespace fipa::acl;
54 
55  MessageParser parser;
56  ACLMessage msg;
57  bool success = parser.parseData(storage, msg);
58 
59  if(success)
60  {
61  std::cout << "------------------------------------\n";
62  std::cout << " Parsing succeeded\n";
63  std::cout << "------------------------------------\n";
64  std::cout << msg.toString() << std::endl;
65 
66 
67  return true;
68  } else {
69 
70  std::cout << " Parsing failed\n";
71  return false;
72  }
73 }
74 
75 
76 bool parseFile(const std::string& filename)
77 {
78  std::ifstream in(filename.c_str(), std::ios_base::in);
79 
80  if (!in)
81  {
82  std::cerr << "Error: could not open input file: "
83  << filename << std::endl;
84  return 1;
85  }
86 
87  std::string storage;
88 
89  // due to special characters don't use std::copy here
90  char buffer;
91  while(true)
92  {
93  in.get(buffer);
94  if(!in.eof())
95  storage += buffer;
96  else
97  break;
98  }
99 
100 
101  return parseMsg(storage);
102 }
103 
104 
106 {
107 
109  char buffer[512];
110  printf("Performative: \n");
111  //scanf(buffer, "%s");
112  msg.setPerformative("inform");
113 
114  printf("Content: \n");
115  getchar();
116  //scanf(buffer, "%s");
117  msg.setContent("");
118 
119  fipa::acl::MessageGenerator generator;
120  std::string bitefficientMessage = generator.create(msg, fipa::acl::representation::BITEFFICIENT);
121 
122  return parseMsg(bitefficientMessage);
123 }
124 
125 
126 
127 
129 // Main program
131 int main(int argc, char** argv)
132 {
133 
134  if( !usage(argc, argv) )
135  return 0;
136 
137  std::string filename;
138  if( ( filename = options["binary-msg-file"]) != "")
139  {
140  parseFile(filename);
141  } else if (options["interactive"] != "")
142  {
143  parseInteractive();
144  } else
145  {
146  info(argv);
147  }
148 
149  return 0;
150 }
151 
bool parseFile(const std::string &filename)
Definition: main.cpp:76
static bool parseData(const std::string &storage, ACLMessage &msg, fipa::acl::representation::Type representation=fipa::acl::representation::BITEFFICIENT)
parses a correctly encoded message according to grammar_bitefficient.h and creates a Message object f...
std::map< std::string, std::string > options
Definition: main.cpp:15
bool usage(int argc, char **argv)
Definition: main.cpp:26
bool parseMsg(const std::string &storage)
Definition: main.cpp:51
static std::string create(const ACLMessage &msg, const representation::Type &acl_representation)
Allows to parse a bytestream that conforms to the bitefficient representation of FIPA messages to a A...
void setContent(const std::string &content)
Definition: acl_message.h:274
This class provides a representation of a message conforming to the FIPA specification SC00061...
Definition: acl_message.h:55
bool parseInteractive()
Definition: main.cpp:105
std::string toString() const
void info(char **argv)
Definition: main.cpp:18
void setPerformative(Performative perf)
Set performative.
int main(int argc, char **argv)
Definition: main.cpp:7
Agent Communication Language.
Definition: conversation.cpp:7