-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
58 lines (46 loc) · 1.37 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
//
// Author: Ugo Pattacini - <ugo.pattacini@iit.it>
#include <cstdlib>
#include <cmath>
#include <string>
#include <yarp/os/Network.h>
#include <yarp/os/LogStream.h>
#include <yarp/os/Bottle.h>
#include <yarp/os/Port.h>
using namespace std;
using namespace yarp::os;
/***************************************************/
int main()
{
// init link to YARP network
Network yarp;
if (!yarp.checkNetwork())
{
yError()<<"YARP doesn't seem to be available";
return EXIT_FAILURE;
}
// open a port to receive requests
Port port;
port.open("/service");
// wait for the incoming request
Bottle request;
port.read(request,true);
// retrieve the request payload
// we'll make sure not to send you 1; trust us ;)
int num=request.get(0).asInt32();
// process the payload
bool isNumEven=true; // FILL IN THE CODE
bool isNumPrime=true; // FILL IN THE CODE
// build the response
string parity=(isNumEven?"even":"odd");
string primality=(isNumPrime?"prime":"composite");
Bottle response;
response.addString("parity-dummy"); // FILL IN THE CODE
response.addString("primality-dummy"); // FILL IN THE CODE
// send back the response
port.reply(response);
// shut down
port.close();
return EXIT_SUCCESS;
}