-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_utils.cpp
More file actions
100 lines (70 loc) · 2.09 KB
/
client_utils.cpp
File metadata and controls
100 lines (70 loc) · 2.09 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "globals.hpp"
#include "node_controller.hpp"
#include "client_utils.hpp"
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/un.h>
#include <netdb.h>
#include <cstdio>
#include <stdlib.h>
#include <unistd.h>
#include <cstring>
using namespace std;
namespace
{
union MessageContainer
{
clientUtils::Message message;
char bytestream[sizeof (message )];
} ;
}
const char*
clientUtils::ClientSock_template( "/tmp/local_client_sock_%u.sock" );
namespace clientUtils
{
//these do not need to convert byte ordres--just use the
//union to convert the bytestream to the client_msg then
//client2internal will convert client_msg to internal_msg
void host2network_msg( const Message& msg, char* buffer )
{
MessageContainer converter;
converter.message = msg;
for ( int itr = 0; itr < sizeof (converter.bytestream );
( buffer[itr] = converter.bytestream[itr] ), itr++ );
return;
}
void network2host_msg( Message& msg, const char* buffer )
{
MessageContainer converter;
for ( int itr = 0; itr < sizeof (converter.bytestream );
( converter.bytestream[itr] = buffer[itr] ), itr++ );
msg = converter.message;
return;
}
std::ostream& operator<<( std::ostream& os, MESSAGE_T mtype )
{
switch ( mtype ) {
case MESSAGE_T::FINISHED:
os << "CLIENT_FINISHED";
break;
case MESSAGE_T::LOCAL_REQUEST:
os << "CLIENT_REQUEST";
break;
case MESSAGE_T::PERMISSION_GRANTED:
os << "CLIENT_PERMISSION_GRANTED";
break;
}
os << endl;
return os;
}
std::ostream& operator<<( std::ostream& os, const Message& msg )
{
os << "Message Type: " << ( msg.type )
<< "Action: " << ( msg.act )
<< "subAction: " << ( msg.subact )
<< "local PID: " << msg.localPID << endl;
return os;
}
}