-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.cpp
More file actions
35 lines (30 loc) · 1.3 KB
/
client.cpp
File metadata and controls
35 lines (30 loc) · 1.3 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
#include "Datastructs.hpp"
#include "Pipes.hpp"
#include "Settings.hpp"
#include "Channel.hpp"
#include "MessageType.hpp"
#include <cstdlib>
#include <iostream>
#include <stdexcept>
int main(int argc, char **argv) try {
Message outgoingMsg, incomingMsg;
ChannelSettings channelSettings = loadStruct<ChannelSettings>(::CHANNEL_INFO_PATH);
Channel<Message> channel(channelSettings.channel_id, channelSettings.parent_pid);
int number;
std::cout << "[C] Prosze podac liczba, ktora ma zostac zamieniona na postac binarna: ";
std::cin >> number;
outgoingMsg.messageType = MessageType::M_DEC2BIN;
outgoingMsg.store<int>(number, 0u);
std::cout << "[C] Czekanie na forme binarna liczby " << number << "...\n";
channel.send(outgoingMsg, incomingMsg);
if(incomingMsg.messageType == MessageType::ERROR) {
std::cerr << "[C] Wystapil blad podczas wykonania polecenia: " << incomingMsg.message << '\n';
} else if(incomingMsg.messageType == MessageType::R_DEC2BIN) {
std::cout << "[C] Liczba " << number << " w postaci binarnej: " << incomingMsg.load<int>(0u) << '\n';
} else {
std::cerr << "[C] Otrzymano odpowiedź zwrotną o nieoczekiwanym typie: " << incomingMsg.messageType << '\n';
}
return EXIT_SUCCESS;
} catch (std::runtime_error err) {
std::cerr << "[C] " << err.what() << std::endl;
}