fipa_acl
1.4
Main Page
Namespaces
Classes
Files
File List
File Members
build
rock-master-18.09-multiagent-fipa-acl-0.20180914
src
message_parser
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
105
bool
parseInteractive
()
106
{
107
108
fipa::acl::ACLMessage
msg;
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
parseFile
bool parseFile(const std::string &filename)
Definition:
main.cpp:76
options
std::map< std::string, std::string > options
Definition:
main.cpp:15
usage
bool usage(int argc, char **argv)
Definition:
main.cpp:26
parseMsg
bool parseMsg(const std::string &storage)
Definition:
main.cpp:51
fipa::acl::MessageGenerator::create
static std::string create(const ACLMessage &msg, const representation::Type &acl_representation)
Definition:
message_generator.cpp:18
fipa::acl::MessageGenerator
Definition:
message_generator.h:15
fipa::acl::MessageParser
Allows to parse a bytestream that conforms to the bitefficient representation of FIPA messages to a A...
Definition:
message_parser.h:28
fipa::acl::representation::BITEFFICIENT
Definition:
types.h:26
fipa::acl::ACLMessage::setContent
void setContent(const std::string &content)
Definition:
acl_message.h:274
fipa::acl::ACLMessage
This class provides a representation of a message conforming to the FIPA specification SC00061...
Definition:
acl_message.h:55
parseInteractive
bool parseInteractive()
Definition:
main.cpp:105
fipa::acl::ACLMessage::toString
std::string toString() const
Definition:
acl_message.cpp:363
info
void info(char **argv)
Definition:
main.cpp:18
fipa::acl::ACLMessage::setPerformative
void setPerformative(Performative perf)
Set performative.
Definition:
acl_message.cpp:121
main
int main(int argc, char **argv)
Definition:
main.cpp:7
Generated on Tue Oct 9 2018 11:04:42 for fipa_acl by
1.8.6