fipa_acl  1.4
Functions | Variables
main.cpp File Reference

Message parser for FIPA ACL Messages, based on boost::spirit. More...

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <fipa_acl/fipa_acl.h>

Go to the source code of this file.

Functions

void info (char **argv)
 
bool usage (int argc, char **argv)
 
bool parseMsg (const std::string &storage)
 
bool parseFile (const std::string &filename)
 
bool parseInteractive ()
 
int main (int argc, char **argv)
 

Variables

std::map< std::string,
std::string > 
options
 

Detailed Description

Message parser for FIPA ACL Messages, based on boost::spirit.

Author
Thomas Roehr, thoma.nosp@m.s.ro.nosp@m.ehr@d.nosp@m.fki..nosp@m.de

Definition in file main.cpp.

Function Documentation

void info ( char **  argv)

Definition at line 18 of file main.cpp.

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 }
int main ( int  argc,
char **  argv 
)

Definition at line 131 of file main.cpp.

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 }
bool parseFile(const std::string &filename)
Definition: main.cpp:76
std::map< std::string, std::string > options
Definition: main.cpp:15
bool usage(int argc, char **argv)
Definition: main.cpp:26
bool parseInteractive()
Definition: main.cpp:105
void info(char **argv)
Definition: main.cpp:18
bool parseFile ( const std::string &  filename)

Definition at line 76 of file main.cpp.

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 }
bool parseMsg(const std::string &storage)
Definition: main.cpp:51
bool parseInteractive ( )

Definition at line 105 of file main.cpp.

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 }
bool parseMsg(const std::string &storage)
Definition: main.cpp:51
static std::string create(const ACLMessage &msg, const representation::Type &acl_representation)
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
void setPerformative(Performative perf)
Set performative.
bool parseMsg ( const std::string &  storage)

Definition at line 51 of file main.cpp.

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 }
Allows to parse a bytestream that conforms to the bitefficient representation of FIPA messages to a A...
This class provides a representation of a message conforming to the FIPA specification SC00061...
Definition: acl_message.h:55
std::string toString() const
bool usage ( int  argc,
char **  argv 
)

Definition at line 26 of file main.cpp.

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 }
std::map< std::string, std::string > options
Definition: main.cpp:15
void info(char **argv)
Definition: main.cpp:18

Variable Documentation

std::map<std::string, std::string> options

Definition at line 15 of file main.cpp.