Fail* directories reorganized, Code-cleanup (-> coding-style), Typos+comments fixed.

git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1321 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
adrian
2012-06-08 20:09:43 +00:00
parent d474a5b952
commit 2575604b41
866 changed files with 1848 additions and 1879 deletions

View File

@ -0,0 +1,8 @@
set(SRCS
SocketComm.cc
)
add_subdirectory(msg)
add_library(comm ${SRCS})
add_dependencies(comm msg)

View File

@ -0,0 +1,50 @@
/**
* \brief This is the base class for all user-defined data types for
* expirement parameter and results.
*/
#ifndef __EXPERIMENT_DATA_HPP__
#define __EXPERIMENT_DATA_HPP__
#include <string>
#include <google/protobuf/message.h>
namespace fail {
/**
* \class ExperimentData
* Container for experiment data with wrapper methods for serialization and deserialization.
*/
class ExperimentData {
protected:
google::protobuf::Message* msg;
uint32_t m_workloadID;
public:
ExperimentData() : msg(0), m_workloadID(0) {};
ExperimentData(google::protobuf::Message* m) : msg(m) , m_workloadID(0) { }
google::protobuf::Message& getMessage() { return *msg; }
uint32_t getWorkloadID() const { return m_workloadID; };
void setWorkloadID(uint32_t id) { m_workloadID = id; }
/**
* Serializes the ExperimentData.
* @param ped output the target-stream.
* @return \c true if the serialization was successful, \c false otherwise
*/
bool serialize(std::ostream* output) const { return msg->SerializeToOstream(output); }
/**
* Unserializes the ExperimentData.
* @param ped input the stream which is read from
* @return \c true if the unserialization was successful, \c false otherwise
*/
bool unserialize(std::istream* input) { return msg->ParseFromIstream(input); }
/**
* Returns a debug string.
* @return the debug string
*/
std::string debugString() const { return msg->DebugString(); };
};
} // end-of-namespace: fail
#endif //__EXPERIMENT_DATA_HPP__

View File

@ -0,0 +1,52 @@
#include <string>
#include "SocketComm.hpp"
namespace fail {
bool SocketComm::sendMsg(int sockfd, google::protobuf::Message& msg)
{
#ifdef USE_SIZE_PREFIX
int size = htonl(msg.ByteSize());
if (write(sockfd, &size, sizeof(size)) != sizeof(size)) {
return false;
}
std::string buf;
msg.SerializeToString(&buf);
if (write(sockfd, buf.c_str(), buf.size()) != (ssize_t) buf.size()) {
return false;
}
#else
char c = 0;
if (!msg.SerializeToFileDescriptor(sockfd) || write(sockfd, &c, 1) != 1) {
return false;
}
#endif
return true;
}
bool SocketComm::rcvMsg(int sockfd, google::protobuf::Message& msg)
{
#ifdef USE_SIZE_PREFIX
int size;
// FIXME: read() may need to be called multiple times until all data was read
if (read(sockfd, &size, sizeof(size)) != sizeof(size)) {
return false;
}
size = ntohl(size);
char *buf = new char[size];
// FIXME: read() may need to be called multiple times until all data was read
if (read(sockfd, buf, size) != size) {
delete [] buf;
return false;
}
std::string st(buf, size);
delete [] buf;
msg.ParseFromString(st);
return true;
#else
return msg.ParseFromFileDescriptor(sockfd);
#endif
}
} // end-of-namespace: fail

View File

@ -0,0 +1,41 @@
/**
* \brief Socket based communictaion wrapper functions.
*/
#ifndef __SOCKET_COMM_HPP__
#define __SOCKET_COMM_HPP__
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <iostream>
#include <fstream>
#include <google/protobuf/message.h>
#define USE_SIZE_PREFIX
namespace fail {
class SocketComm {
public:
/**
* Send Protobuf-generated message
* @param sockfd open socket descriptor to write to
* @param Msg Reference to Protobuf generated message type
* \return false if message sending failed
*/
static bool sendMsg(int sockfd, google::protobuf::Message& msg);
/**
* Receive Protobuf-generated message
* @param sockfd open socket descriptor to read from
* @param Msg Reference to Protobuf generated message type
* \return false if message reception failed
*/
static bool rcvMsg(int sockfd, google::protobuf::Message& msg);
};
} // end-of-namespace: fail
#endif // __SOCKET_COMM_HPP__

View File

@ -0,0 +1,15 @@
## Setup desired protobuf descriptions HERE ##
set(MY_PROTOS
FailControlMessage.proto
)
#### PROTOBUFS ####
find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${MY_PROTOS})
## Build library
add_library(msg ${PROTO_SRCS} ${PROTO_HDRS})

View File

@ -0,0 +1,16 @@
message FailControlMessage {
enum Command {
// Minions may send these:
NEED_WORK = 0; // server replies with WORK_FOLLOWS or DIE
RESULT_FOLLOWS = 1; // followed by experiment-specific ExperimentData message (holding both original parameters and experiment result)
// JobServer may send these:
WORK_FOLLOWS = 5; // followed by experiment-specific ExperimentData message
COME_AGAIN = 6; // no experiment-specific ExperimentData at the moment, but Campaign is not over yet
DIE = 7; // tells the client to terminate
}
required Command command = 1;
optional uint32 workloadID = 2;
required uint64 build_id = 3; // identifying the client/server build (e.g., build time in unixtime format)
}

2
src/core/comm/msg/protogen.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
protoc --cpp_out=. FailControlMessage.proto