Skip to content

Commit 2aacf78

Browse files
authored
Refactor comms naming to match other modules (#16)
1 parent c452af2 commit 2aacf78

12 files changed

+359
-360
lines changed

source_common/comms/comms_interface.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class CommsInterface
7070
*
7171
* @return Returns @c true if connected, @c false otherwise.
7272
*/
73-
virtual bool is_connected() = 0;
73+
virtual bool isConnected() = 0;
7474

7575
/**
7676
* @brief Get the service endpoint address for the named service.
@@ -79,7 +79,7 @@ class CommsInterface
7979
*
8080
* @return The service address, or @c NO_ENDPOINT if service is not found.
8181
*/
82-
virtual EndpointID get_endpoint_id(
82+
virtual EndpointID getEndpointID(
8383
const std::string& name) = 0;
8484

8585
/**
@@ -91,7 +91,7 @@ class CommsInterface
9191
* @param endpoint The address of the destination service.
9292
* @param data The data to transmit.
9393
*/
94-
virtual void tx_async(
94+
virtual void txAsync(
9595
EndpointID endpoint,
9696
std::unique_ptr<MessageData> data) = 0;
9797

@@ -122,7 +122,7 @@ class CommsInterface
122122
*
123123
* @return The response message data payload.
124124
*/
125-
virtual std::unique_ptr<MessageData> tx_rx(
125+
virtual std::unique_ptr<MessageData> txRx(
126126
EndpointID endpoint,
127127
std::unique_ptr<MessageData> data) = 0;
128128
};

source_common/comms/comms_message.hpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ enum class MessageType: uint8_t {
5959
*/
6060
typedef struct __attribute__((packed))
6161
{
62-
uint8_t message_type; // Is this tx_async (0), tx (1), or tx_rx (2)?
63-
uint8_t endpoint_id; // The endpoint service address.
64-
uint64_t message_id; // The unique message ID for a tx_rx pair.
65-
uint32_t payload_size; // The size of the payload in bytes.
62+
uint8_t messageType; // Is this tx_async (0), tx (1), or tx_rx (2)?
63+
uint8_t endpointID; // The endpoint service address.
64+
uint64_t messageID; // The unique message ID for a tx_rx pair.
65+
uint32_t payloadSize; // The size of the payload in bytes.
6666
} MessageHeader;
6767

6868
/**
@@ -74,53 +74,53 @@ class Message: public Task
7474
/**
7575
* @brief Construct a new message.
7676
*
77-
* @param endpoint_id The destination endpoint.
78-
* @param message_type The type of the message.
79-
* @param message_id The sequence ID of the message.
80-
* @param transmit_data The data to transmit.
77+
* @param endpointID The destination endpoint.
78+
* @param messageType The type of the message.
79+
* @param messageID The sequence ID of the message.
80+
* @param transmitData The data to transmit.
8181
*/
8282
Message(
83-
EndpointID endpoint_id,
84-
MessageType message_type,
85-
MessageID message_id,
86-
std::unique_ptr<MessageData> transmit_data) :
87-
endpoint_id(endpoint_id),
88-
message_type(message_type),
89-
message_id(message_id),
90-
transmit_data(std::move(transmit_data)) { }
83+
EndpointID endpointID,
84+
MessageType messageType,
85+
MessageID messageID,
86+
std::unique_ptr<MessageData> transmitData) :
87+
endpointID(endpointID),
88+
messageType(messageType),
89+
messageID(messageID),
90+
transmitData(std::move(transmitData)) { }
9191

9292
/**
9393
* @brief The type of the message.
9494
*/
95-
EndpointID endpoint_id;
95+
EndpointID endpointID;
9696

9797
/**
9898
* @brief The type of the message.
9999
*/
100-
MessageType message_type;
100+
MessageType messageType;
101101

102102
/**
103103
* @brief The sequence ID of the message.
104104
*
105-
* Only required if @c message_type is @c TX_RX and we have to match a
105+
* Only required if @c messageType is @c TX_RX and we have to match a
106106
* response to a triggering message.
107107
*/
108-
MessageID message_id;
108+
MessageID messageID;
109109

110110
/**
111111
* @brief The data to transmit.
112112
*
113113
* Can be reset and data discarded once the data is transmitted.
114114
*/
115-
std::unique_ptr<MessageData> transmit_data;
115+
std::unique_ptr<MessageData> transmitData;
116116

117117
/**
118118
* @brief The data that was received.
119119
*
120-
* Only present if @c message_type is @c TX_RX and we have received a
120+
* Only present if @c messageType is @c TX_RX and we have received a
121121
* response from the host.
122122
*/
123-
std::unique_ptr<MessageData> response_data;
123+
std::unique_ptr<MessageData> responseData;
124124
};
125125

126126
}

source_common/comms/comms_module.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace Comms
4343

4444
/** See header for documentation. */
4545
CommsModule::CommsModule(
46-
const std::string& domain_address
46+
const std::string& domainAddress
4747
) {
4848
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
4949
if (sockfd < 0)
@@ -52,17 +52,17 @@ CommsModule::CommsModule(
5252
return;
5353
}
5454

55-
struct sockaddr_un serv_addr {};
56-
serv_addr.sun_family = AF_UNIX;
55+
struct sockaddr_un servAddr {};
56+
servAddr.sun_family = AF_UNIX;
5757

5858
// Copy the domain address, inserting leading NUL needed for abstract UDS
59-
std::strcpy(serv_addr.sun_path + 1, domain_address.c_str());
60-
serv_addr.sun_path[0] = '\0';
59+
std::strcpy(servAddr.sun_path + 1, domainAddress.c_str());
60+
servAddr.sun_path[0] = '\0';
6161

6262
int conn = connect(
6363
sockfd,
64-
reinterpret_cast<const struct sockaddr*>(&serv_addr),
65-
sizeof(serv_addr));
64+
reinterpret_cast<const struct sockaddr*>(&servAddr),
65+
sizeof(servAddr));
6666
if (conn != 0)
6767
{
6868
std::cout << " - ERROR: Client connection failed" << std::endl;
@@ -77,7 +77,7 @@ CommsModule::CommsModule(
7777

7878
/** See header for documentation. */
7979
CommsModule::CommsModule(
80-
const std::string& host_address,
80+
const std::string& hostAddress,
8181
int port
8282
) {
8383
sockfd = socket(AF_INET, SOCK_STREAM, 0);
@@ -87,15 +87,15 @@ CommsModule::CommsModule(
8787
return;
8888
}
8989

90-
struct sockaddr_in serv_addr {};
91-
serv_addr.sin_family = AF_INET;
92-
serv_addr.sin_port = htons(port);
93-
serv_addr.sin_addr.s_addr = inet_addr(host_address.c_str());
90+
struct sockaddr_in servAddr {};
91+
servAddr.sin_family = AF_INET;
92+
servAddr.sin_port = htons(port);
93+
servAddr.sin_addr.s_addr = inet_addr(hostAddress.c_str());
9494

9595
int conn = connect(
9696
sockfd,
97-
reinterpret_cast<const struct sockaddr*>(&serv_addr),
98-
sizeof(serv_addr));
97+
reinterpret_cast<const struct sockaddr*>(&servAddr),
98+
sizeof(servAddr));
9999
if (conn != 0)
100100
{
101101
std::cout << " - ERROR: Client connection failed" << std::endl;
@@ -132,21 +132,21 @@ CommsModule::~CommsModule()
132132
}
133133

134134
/** See header for documentation. */
135-
bool CommsModule::is_connected()
135+
bool CommsModule::isConnected()
136136
{
137137
return sockfd >= 0;
138138
}
139139

140140
/** See header for documentation. */
141-
EndpointID CommsModule::get_endpoint_id(
141+
EndpointID CommsModule::getEndpointID(
142142
const std::string& name
143143
) {
144-
std::lock_guard<std::mutex> lock(registry_lock);
144+
std::lock_guard<std::mutex> lock(registryLock);
145145
if (registry.empty())
146146
{
147147
// Request the registry from the host
148148
auto data = std::make_unique<std::vector<uint8_t>>();
149-
auto resp = tx_rx(0, std::move(data));
149+
auto resp = txRx(0, std::move(data));
150150

151151
// Process the response
152152
while (resp->size())
@@ -192,7 +192,7 @@ EndpointID CommsModule::get_endpoint_id(
192192
}
193193

194194
/** See header for documentation. */
195-
void CommsModule::tx_async(
195+
void CommsModule::txAsync(
196196
EndpointID endpoint,
197197
std::unique_ptr<MessageData> data
198198
) {
@@ -202,7 +202,7 @@ void CommsModule::tx_async(
202202
0,
203203
std::move(data));
204204

205-
enqueue_message(std::move(message));
205+
enqueueMessage(std::move(message));
206206
}
207207

208208
/** See header for documentation. */
@@ -216,44 +216,44 @@ void CommsModule::tx(
216216
0,
217217
std::move(data));
218218

219-
enqueue_message(message);
219+
enqueueMessage(message);
220220
message->wait();
221221
}
222222

223223
/** See header for documentation. */
224-
std::unique_ptr<MessageData> CommsModule::tx_rx(
224+
std::unique_ptr<MessageData> CommsModule::txRx(
225225
EndpointID endpoint,
226226
std::unique_ptr<MessageData> data
227227
) {
228228
auto message = std::make_shared<Message>(
229229
endpoint,
230230
MessageType::TX_RX,
231-
assign_message_id(),
231+
assignMessageID(),
232232
std::move(data));
233233

234-
enqueue_message(message);
234+
enqueueMessage(message);
235235
message->wait();
236236

237-
return std::move(message->response_data);
237+
return std::move(message->responseData);
238238
}
239239

240240
/** See header for documentation. */
241-
MessageID CommsModule::assign_message_id()
241+
MessageID CommsModule::assignMessageID()
242242
{
243-
return next_message_id.fetch_add(1, std::memory_order_relaxed);
243+
return nextMessageID.fetch_add(1, std::memory_order_relaxed);
244244
}
245245

246246
/** See header for documentation. */
247-
void CommsModule::enqueue_message(
247+
void CommsModule::enqueueMessage(
248248
std::shared_ptr<Message> message
249249
) {
250-
message_queue.put(std::move(message));
250+
messageQueue.put(std::move(message));
251251
}
252252

253253
/** See header for documentation. */
254-
std::shared_ptr<Message> CommsModule::dequeue_message()
254+
std::shared_ptr<Message> CommsModule::dequeueMessage()
255255
{
256-
return message_queue.get();
256+
return messageQueue.get();
257257
}
258258

259259
}

0 commit comments

Comments
 (0)