Skip to content

Commit

Permalink
Apply formating, clientId in COMPARE response
Browse files Browse the repository at this point in the history
  • Loading branch information
ben committed Aug 10, 2024
1 parent ae94c16 commit f95a0ce
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 25 deletions.
90 changes: 90 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"files.associations": {
"__bit_reference": "cpp",
"__bits": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__tuple": "cpp",
"__verbose_abort": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"queue": "cpp",
"ratio": "cpp",
"set": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"variant": "cpp",
"vector": "cpp",
"__nullptr": "cpp",
"__string": "cpp",
"chrono": "cpp",
"compare": "cpp",
"concepts": "cpp",
"algorithm": "cpp",
"*.tcc": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"utility": "cpp",
"charconv": "cpp",
"execution": "cpp"
}
}
4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct ConnectionsInfo

int main(int argc, char *argv[])
{
const std::string shared_memory_name{"/shared_mem_1"};
const std::string shared_memory_name{"/shared_mem_"};
bool isStopRequested{false}, connectionConfirmed{false};
std::unique_ptr<ProcCommunicator> slave = std::make_unique<ProcCommunicator>(false, true, shared_memory_name);
am::configuration::Configuration default_conf{75, 10, 1, 50, 5, 10.0};
Expand Down Expand Up @@ -155,7 +155,7 @@ int main(int argc, char *argv[])
auto result = amApi->compare(messageCompare->base, messageCompare->to_compare);
std::cout << "received after compare\n";
MessageCompareResult compare_result;
compare_result.id = 1;
compare_result.id = messageCompare->id;

compare_result.payload_bytes = result.size() * sizeof(Rect);
Rect *rects = static_cast<Rect *>(compare_result.payload);
Expand Down
20 changes: 10 additions & 10 deletions sh_mem/ProcCommunicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ ProcCommunicator::ProcCommunicator(const bool isMasterMode,
m_sender = std::make_unique<SharedMemorySender>(master_mem_name.c_str());
m_receiver = std::make_unique<SharedMemoryReceiver>(slave_mem_name.c_str());

m_master_received = sem_open((shMemName+"_m_rsem").c_str(), O_CREAT, 0666, SEMAPHORE_DISABLED);
m_slave_received = sem_open((shMemName+"_s_rsem").c_str(), O_CREAT, 0666, SEMAPHORE_DISABLED);
m_master_sent = sem_open((shMemName+"_m_sent").c_str(), O_CREAT, 0666, SEMAPHORE_DISABLED);
m_slave_sent = sem_open((shMemName+"_s_sent").c_str(), O_CREAT, 0666, SEMAPHORE_DISABLED);
m_master_received = sem_open((shMemName + "_m_rsem").c_str(), O_CREAT, 0666, SEMAPHORE_DISABLED);
m_slave_received = sem_open((shMemName + "_s_rsem").c_str(), O_CREAT, 0666, SEMAPHORE_DISABLED);
m_master_sent = sem_open((shMemName + "_m_sent").c_str(), O_CREAT, 0666, SEMAPHORE_DISABLED);
m_slave_sent = sem_open((shMemName + "_s_sent").c_str(), O_CREAT, 0666, SEMAPHORE_DISABLED);

if (isMultipleMasters)
m_slave_ready = sem_open((shMemName+"_s_ready").c_str(), O_CREAT, 0666, SEMAPHORE_ENABLED);
m_slave_ready = sem_open((shMemName + "_s_ready").c_str(), O_CREAT, 0666, SEMAPHORE_ENABLED);

if (m_master_received == SEM_FAILED || m_slave_received == SEM_FAILED ||
m_master_sent == SEM_FAILED || m_slave_sent == SEM_FAILED || m_slave_ready == SEM_FAILED)
Expand All @@ -43,13 +43,13 @@ ProcCommunicator::ProcCommunicator(const bool isMasterMode,
while (m_master_received == SEM_FAILED || m_slave_received == SEM_FAILED ||
m_master_sent == SEM_FAILED || m_slave_sent == SEM_FAILED || m_slave_ready == SEM_FAILED)
{
m_master_received = sem_open((shMemName+"_m_rsem").c_str(), O_RDWR, 0666, SEMAPHORE_DISABLED);
m_slave_received = sem_open((shMemName+"_s_rsem").c_str(), O_RDWR, 0666, SEMAPHORE_DISABLED);
m_master_sent = sem_open((shMemName+"_m_sent").c_str(), O_RDWR, 0666, SEMAPHORE_DISABLED);
m_slave_sent = sem_open((shMemName+"_s_sent").c_str(), O_RDWR, 0666, SEMAPHORE_DISABLED);
m_master_received = sem_open((shMemName + "_m_rsem").c_str(), O_RDWR, 0666, SEMAPHORE_DISABLED);
m_slave_received = sem_open((shMemName + "_s_rsem").c_str(), O_RDWR, 0666, SEMAPHORE_DISABLED);
m_master_sent = sem_open((shMemName + "_m_sent").c_str(), O_RDWR, 0666, SEMAPHORE_DISABLED);
m_slave_sent = sem_open((shMemName + "_s_sent").c_str(), O_RDWR, 0666, SEMAPHORE_DISABLED);

if (isMultipleMasters)
m_slave_ready = sem_open((shMemName+"_s_ready").c_str(), O_RDWR, 0666, SEMAPHORE_ENABLED);
m_slave_ready = sem_open((shMemName + "_s_ready").c_str(), O_RDWR, 0666, SEMAPHORE_ENABLED);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions sh_mem/ProcCommunicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
class ProcCommunicator
{
public:
ProcCommunicator(const bool isMasterMode, const bool isMultipleMasters, const std::string& shMemName);
ProcCommunicator(const bool isMasterMode, const bool isMultipleMasters, const std::string &shMemName);
~ProcCommunicator();

void send(const Message* msg);
Message* receive();
Message* sendAndGetResponse(const Message *msg);
void send(const Message *msg);
Message *receive();
Message *sendAndGetResponse(const Message *msg);

private:
std::unique_ptr<SharedMemorySender> m_sender;
Expand Down
1 change: 0 additions & 1 deletion sh_mem/SharedMemoryReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ void SharedMemoryReceiver::finish()

Message *SharedMemoryReceiver::receiveMessage()
{
//std::cout<<"receiveMessage\n";
Message *message(static_cast<Message *>(m_ptr));
return message;
}
3 changes: 1 addition & 2 deletions sh_mem/SharedMemoryReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ class SharedMemoryReceiver
SharedMemoryReceiver(const char *shMemName);
void init();
void finish();
Message * receiveMessage();
Message *receiveMessage();

private:
int m_shm_fd;
void *m_ptr;
sem_t *m_sem;
sem_t *m_rec_sem;
std::string m_name;

};
9 changes: 3 additions & 6 deletions sh_mem/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <iostream>
#include <thread>
#include <chrono>
#include<mutex>
#include <mutex>

static const std::string shared_mem_name{"/sh_mem5"};

Expand All @@ -19,12 +19,9 @@ void backgroundTask()
{
{
Message msg{777, MessageType::HANDSHAKE_OK};
Message* res = slave->receive();
//std::cout << res.id << std::endl;
Message *res = slave->receive();
msg.id = res->id;
//std::cout << msg.id << std::endl;
slave->send(&msg);
//std::cout << res.id << " -> " << msg.id << "." << std::endl;
counter++;
}
}
Expand Down Expand Up @@ -71,7 +68,7 @@ int main()
{
master.send(&msg_hand);
auto msg_resp = master.receive();
//std::cout << "m 2 " << msg_resp->id << std::endl;
// std::cout << "m 2 " << msg_resp->id << std::endl;
counter++;
}

Expand Down

0 comments on commit f95a0ce

Please sign in to comment.