use clang-format for FairMQ

This commit is contained in:
Alexey Rybalchenko
2014-04-10 15:20:48 +02:00
parent e80e6d4269
commit 68d51d8ed5
55 changed files with 1893 additions and 1759 deletions

View File

@@ -11,37 +11,41 @@
FairMQContextZMQ::FairMQContextZMQ(int numIoThreads)
{
fContext = zmq_ctx_new ();
if (fContext == NULL){
LOG(ERROR) << "failed creating context, reason: " << zmq_strerror(errno);
}
fContext = zmq_ctx_new();
if (fContext == NULL)
{
LOG(ERROR) << "failed creating context, reason: " << zmq_strerror(errno);
}
int rc = zmq_ctx_set (fContext, ZMQ_IO_THREADS, numIoThreads);
if (rc != 0){
LOG(ERROR) << "failed configuring context, reason: " << zmq_strerror(errno);
}
int rc = zmq_ctx_set(fContext, ZMQ_IO_THREADS, numIoThreads);
if (rc != 0)
{
LOG(ERROR) << "failed configuring context, reason: " << zmq_strerror(errno);
}
}
FairMQContextZMQ::~FairMQContextZMQ()
{
Close();
Close();
}
void* FairMQContextZMQ::GetContext()
{
return fContext;
return fContext;
}
void FairMQContextZMQ::Close()
{
if (fContext == NULL){
return;
}
if (fContext == NULL)
{
return;
}
int rc = zmq_ctx_destroy (fContext);
if (rc != 0) {
LOG(ERROR) << "failed closing context, reason: " << zmq_strerror(errno);
}
int rc = zmq_ctx_destroy(fContext);
if (rc != 0)
{
LOG(ERROR) << "failed closing context, reason: " << zmq_strerror(errno);
}
fContext = NULL;
fContext = NULL;
}

View File

@@ -11,104 +11,110 @@
#include "FairMQMessageZMQ.h"
#include "FairMQLogger.h"
FairMQMessageZMQ::FairMQMessageZMQ()
{
int rc = zmq_msg_init (&fMessage);
if (rc != 0) {
LOG(ERROR) << "failed initializing message, reason: " << zmq_strerror(errno);
}
int rc = zmq_msg_init(&fMessage);
if (rc != 0)
{
LOG(ERROR) << "failed initializing message, reason: " << zmq_strerror(errno);
}
}
FairMQMessageZMQ::FairMQMessageZMQ(size_t size)
{
int rc = zmq_msg_init_size (&fMessage, size);
if (rc != 0) {
LOG(ERROR) << "failed initializing message with size, reason: " << zmq_strerror(errno);
}
int rc = zmq_msg_init_size(&fMessage, size);
if (rc != 0)
{
LOG(ERROR) << "failed initializing message with size, reason: " << zmq_strerror(errno);
}
}
FairMQMessageZMQ::FairMQMessageZMQ(void* data, size_t size)
{
int rc = zmq_msg_init_data (&fMessage, data, size, &CleanUp, NULL);
if (rc != 0) {
LOG(ERROR) << "failed initializing message with data, reason: " << zmq_strerror(errno);
}
int rc = zmq_msg_init_data(&fMessage, data, size, &CleanUp, NULL);
if (rc != 0)
{
LOG(ERROR) << "failed initializing message with data, reason: " << zmq_strerror(errno);
}
}
void FairMQMessageZMQ::Rebuild()
{
CloseMessage();
int rc = zmq_msg_init (&fMessage);
if (rc != 0) {
LOG(ERROR) << "failed initializing message, reason: " << zmq_strerror(errno);
}
CloseMessage();
int rc = zmq_msg_init(&fMessage);
if (rc != 0)
{
LOG(ERROR) << "failed initializing message, reason: " << zmq_strerror(errno);
}
}
void FairMQMessageZMQ::Rebuild(size_t size)
{
CloseMessage();
int rc = zmq_msg_init_size (&fMessage, size);
if (rc != 0) {
LOG(ERROR) << "failed initializing message with size, reason: " << zmq_strerror(errno);
}
CloseMessage();
int rc = zmq_msg_init_size(&fMessage, size);
if (rc != 0)
{
LOG(ERROR) << "failed initializing message with size, reason: " << zmq_strerror(errno);
}
}
void FairMQMessageZMQ::Rebuild(void* data, size_t size)
{
CloseMessage();
int rc = zmq_msg_init_data (&fMessage, data, size, &CleanUp, NULL);
if (rc != 0) {
LOG(ERROR) << "failed initializing message with data, reason: " << zmq_strerror(errno);
}
CloseMessage();
int rc = zmq_msg_init_data(&fMessage, data, size, &CleanUp, NULL);
if (rc != 0)
{
LOG(ERROR) << "failed initializing message with data, reason: " << zmq_strerror(errno);
}
}
void* FairMQMessageZMQ::GetMessage()
{
return &fMessage;
return &fMessage;
}
void* FairMQMessageZMQ::GetData()
{
return zmq_msg_data (&fMessage);
return zmq_msg_data(&fMessage);
}
size_t FairMQMessageZMQ::GetSize()
{
return zmq_msg_size (&fMessage);
return zmq_msg_size(&fMessage);
}
void FairMQMessageZMQ::SetMessage(void* data, size_t size)
{
// dummy method to comply with the interface. functionality not allowed in zeromq.
// dummy method to comply with the interface. functionality not allowed in zeromq.
}
void FairMQMessageZMQ::Copy(FairMQMessage* msg)
{
CloseMessage();
size_t size = msg->GetSize();
zmq_msg_init_size(&fMessage, size);
std::memcpy(zmq_msg_data(&fMessage), msg->GetData(), size);
CloseMessage();
size_t size = msg->GetSize();
zmq_msg_init_size(&fMessage, size);
std::memcpy(zmq_msg_data(&fMessage), msg->GetData(), size);
}
inline void FairMQMessageZMQ::CloseMessage()
{
int rc = zmq_msg_close (&fMessage);
if (rc != 0) {
LOG(ERROR) << "failed closing message, reason: " << zmq_strerror(errno);
}
int rc = zmq_msg_close(&fMessage);
if (rc != 0)
{
LOG(ERROR) << "failed closing message, reason: " << zmq_strerror(errno);
}
}
void FairMQMessageZMQ::CleanUp(void* data, void* hint)
{
free (data);
free(data);
}
FairMQMessageZMQ::~FairMQMessageZMQ()
{
int rc = zmq_msg_close (&fMessage);
if (rc != 0) {
LOG(ERROR) << "failed closing message with data, reason: " << zmq_strerror(errno);
}
int rc = zmq_msg_close(&fMessage);
if (rc != 0)
{
LOG(ERROR) << "failed closing message with data, reason: " << zmq_strerror(errno);
}
}

View File

@@ -14,7 +14,6 @@
#include "FairMQMessage.h"
class FairMQMessageZMQ : public FairMQMessage
{
public:

View File

@@ -11,31 +11,33 @@
FairMQPollerZMQ::FairMQPollerZMQ(const vector<FairMQSocket*>& inputs)
{
fNumItems = inputs.size();
items = new zmq_pollitem_t[fNumItems];
fNumItems = inputs.size();
items = new zmq_pollitem_t[fNumItems];
for (int i = 0; i < fNumItems; i++) {
items[i].socket = inputs.at(i)->GetSocket();
items[i].fd = 0;
items[i].events = ZMQ_POLLIN;
items[i].revents = 0;
}
for (int i = 0; i < fNumItems; i++)
{
items[i].socket = inputs.at(i)->GetSocket();
items[i].fd = 0;
items[i].events = ZMQ_POLLIN;
items[i].revents = 0;
}
}
void FairMQPollerZMQ::Poll(int timeout)
{
zmq_poll(items, fNumItems, timeout);
zmq_poll(items, fNumItems, timeout);
}
bool FairMQPollerZMQ::CheckInput(int index)
{
if (items[index].revents & ZMQ_POLLIN)
return true;
if (items[index].revents & ZMQ_POLLIN)
return true;
return false;
return false;
}
FairMQPollerZMQ::~FairMQPollerZMQ()
{
if (items != NULL) delete [] items;
if (items != NULL)
delete[] items;
}

View File

@@ -39,131 +39,156 @@ FairMQSocketZMQ::FairMQSocketZMQ(const string& type, int num, int numIoThreads)
if (rc != 0) {
LOG(ERROR) << "failed setting socket option, reason: " << zmq_strerror(errno);
}
}
LOG(INFO) << "created socket #" << fId;
if (type == "sub")
{
rc = zmq_setsockopt(fSocket, ZMQ_SUBSCRIBE, NULL, 0);
if (rc != 0)
{
LOG(ERROR) << "failed setting socket option, reason: " << zmq_strerror(errno);
}
}
LOG(INFO) << "created socket #" << fId;
}
string FairMQSocketZMQ::GetId()
{
return fId;
return fId;
}
void FairMQSocketZMQ::Bind(const string& address)
{
LOG(INFO) << "bind socket #" << fId << " on " << address;
LOG(INFO) << "bind socket #" << fId << " on " << address;
int rc = zmq_bind (fSocket, address.c_str());
if (rc != 0) {
LOG(ERROR) << "failed binding socket #" << fId << ", reason: " << zmq_strerror(errno);
}
int rc = zmq_bind(fSocket, address.c_str());
if (rc != 0)
{
LOG(ERROR) << "failed binding socket #" << fId << ", reason: " << zmq_strerror(errno);
}
}
void FairMQSocketZMQ::Connect(const string& address)
{
LOG(INFO) << "connect socket #" << fId << " on " << address;
LOG(INFO) << "connect socket #" << fId << " on " << address;
int rc = zmq_connect (fSocket, address.c_str());
if (rc != 0) {
LOG(ERROR) << "failed connecting socket #" << fId << ", reason: " << zmq_strerror(errno);
}
int rc = zmq_connect(fSocket, address.c_str());
if (rc != 0)
{
LOG(ERROR) << "failed connecting socket #" << fId << ", reason: " << zmq_strerror(errno);
}
}
size_t FairMQSocketZMQ::Send(FairMQMessage* msg)
{
int nbytes = zmq_msg_send (static_cast<zmq_msg_t*>(msg->GetMessage()), fSocket, 0);
if (nbytes >= 0){
fBytesTx += nbytes;
++fMessagesTx;
int nbytes = zmq_msg_send(static_cast<zmq_msg_t*>(msg->GetMessage()), fSocket, 0);
if (nbytes >= 0)
{
fBytesTx += nbytes;
++fMessagesTx;
return nbytes;
}
if (zmq_errno() == EAGAIN)
{
return false;
}
LOG(ERROR) << "failed sending on socket #" << fId << ", reason: " << zmq_strerror(errno);
return nbytes;
}
if (zmq_errno() == EAGAIN){
return false;
}
LOG(ERROR) << "failed sending on socket #" << fId << ", reason: " << zmq_strerror(errno);
return nbytes;
}
size_t FairMQSocketZMQ::Receive(FairMQMessage* msg)
{
int nbytes = zmq_msg_recv (static_cast<zmq_msg_t*>(msg->GetMessage()), fSocket, 0);
if (nbytes >= 0){
fBytesRx += nbytes;
++fMessagesRx;
int nbytes = zmq_msg_recv(static_cast<zmq_msg_t*>(msg->GetMessage()), fSocket, 0);
if (nbytes >= 0)
{
fBytesRx += nbytes;
++fMessagesRx;
return nbytes;
}
if (zmq_errno() == EAGAIN)
{
return false;
}
LOG(ERROR) << "failed receiving on socket #" << fId << ", reason: " << zmq_strerror(errno);
return nbytes;
}
if (zmq_errno() == EAGAIN){
return false;
}
LOG(ERROR) << "failed receiving on socket #" << fId << ", reason: " << zmq_strerror(errno);
return nbytes;
}
void FairMQSocketZMQ::Close()
{
if (fSocket == NULL){
return;
}
if (fSocket == NULL)
{
return;
}
int rc = zmq_close (fSocket);
if (rc != 0) {
LOG(ERROR) << "failed closing socket, reason: " << zmq_strerror(errno);
}
int rc = zmq_close(fSocket);
if (rc != 0)
{
LOG(ERROR) << "failed closing socket, reason: " << zmq_strerror(errno);
}
fSocket = NULL;
fSocket = NULL;
}
void* FairMQSocketZMQ::GetSocket()
{
return fSocket;
return fSocket;
}
int FairMQSocketZMQ::GetSocket(int nothing)
{
// dummy method to comply with the interface. functionality not possible in zeromq.
return -1;
// dummy method to comply with the interface. functionality not possible in zeromq.
return -1;
}
void FairMQSocketZMQ::SetOption(const string& option, const void* value, size_t valueSize)
{
int rc = zmq_setsockopt(fSocket, GetConstant(option), value, valueSize);
if (rc < 0) {
LOG(ERROR) << "failed setting socket option, reason: " << zmq_strerror(errno);
}
int rc = zmq_setsockopt(fSocket, GetConstant(option), value, valueSize);
if (rc < 0)
{
LOG(ERROR) << "failed setting socket option, reason: " << zmq_strerror(errno);
}
}
unsigned long FairMQSocketZMQ::GetBytesTx()
{
return fBytesTx;
return fBytesTx;
}
unsigned long FairMQSocketZMQ::GetBytesRx()
{
return fBytesRx;
return fBytesRx;
}
unsigned long FairMQSocketZMQ::GetMessagesTx()
{
return fMessagesTx;
return fMessagesTx;
}
unsigned long FairMQSocketZMQ::GetMessagesRx()
{
return fMessagesRx;
return fMessagesRx;
}
int FairMQSocketZMQ::GetConstant(const string& constant)
{
if (constant == "sub") return ZMQ_SUB;
if (constant == "pub") return ZMQ_PUB;
if (constant == "xsub") return ZMQ_XSUB;
if (constant == "xpub") return ZMQ_XPUB;
if (constant == "push") return ZMQ_PUSH;
if (constant == "pull") return ZMQ_PULL;
if (constant == "snd-hwm") return ZMQ_SNDHWM;
if (constant == "rcv-hwm") return ZMQ_RCVHWM;
if (constant == "sub")
return ZMQ_SUB;
if (constant == "pub")
return ZMQ_PUB;
if (constant == "xsub")
return ZMQ_XSUB;
if (constant == "xpub")
return ZMQ_XPUB;
if (constant == "push")
return ZMQ_PUSH;
if (constant == "pull")
return ZMQ_PULL;
if (constant == "snd-hwm")
return ZMQ_SNDHWM;
if (constant == "rcv-hwm")
return ZMQ_RCVHWM;
return -1;
return -1;
}
FairMQSocketZMQ::~FairMQSocketZMQ()

View File

@@ -15,7 +15,6 @@
#include "FairMQSocket.h"
#include "FairMQContextZMQ.h"
class FairMQSocketZMQ : public FairMQSocket
{
public:

View File

@@ -11,24 +11,24 @@
FairMQTransportFactoryZMQ::FairMQTransportFactoryZMQ()
{
int major, minor, patch;
zmq_version (&major, &minor, &patch);
LOG(INFO) << "Using ZeroMQ library, version: " << major << "." << minor << "." << patch;
int major, minor, patch;
zmq_version(&major, &minor, &patch);
LOG(INFO) << "Using ZeroMQ library, version: " << major << "." << minor << "." << patch;
}
FairMQMessage* FairMQTransportFactoryZMQ::CreateMessage()
{
return new FairMQMessageZMQ();
return new FairMQMessageZMQ();
}
FairMQMessage* FairMQTransportFactoryZMQ::CreateMessage(size_t size)
{
return new FairMQMessageZMQ(size);
return new FairMQMessageZMQ(size);
}
FairMQMessage* FairMQTransportFactoryZMQ::CreateMessage(void* data, size_t size)
{
return new FairMQMessageZMQ(data, size);
return new FairMQMessageZMQ(data, size);
}
FairMQSocket* FairMQTransportFactoryZMQ::CreateSocket(const string& type, int num, int numIoThreads)
@@ -38,5 +38,5 @@ FairMQSocket* FairMQTransportFactoryZMQ::CreateSocket(const string& type, int nu
FairMQPoller* FairMQTransportFactoryZMQ::CreatePoller(const vector<FairMQSocket*>& inputs)
{
return new FairMQPollerZMQ(inputs);
return new FairMQPollerZMQ(inputs);
}

View File

@@ -27,7 +27,6 @@ class FairMQTransportFactoryZMQ : public FairMQTransportFactory
virtual FairMQSocket* CreateSocket(const string& type, int num, int numIoThreads);
virtual FairMQPoller* CreatePoller(const vector<FairMQSocket*>& inputs);
virtual ~FairMQTransportFactoryZMQ() {};
};