Commit f86198f0 authored by Ciarán Ó Rourke's avatar Ciarán Ó Rourke
Browse files

Ran clang format

parent 9114863f
#include "fiphobo.h"
#include <cstdio>
#include <fcntl.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <cstdio>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
#include "FiPhoExceptions.h"
namespace fiphoboserver
{
namespace fiphoboserver {
FiPhobo::FiPhobo()
{
......@@ -26,23 +25,23 @@ void FiPhobo::setBucketName(std::string bucketName)
std::cout << "Phobos_Layer::setBucketName" << std::endl;
#endif
int rc = pho_attr_set(&descriptor.xd_attrs, "bucket", bucketName.c_str());
if(rc)
{
if (rc) {
throw fiphoexceptions::PhobosException("pho_attr_set", rc);
}
}
void FiPhobo::setMetaData(std::vector<std::pair<std::string, std::string>> metaData)
void FiPhobo::setMetaData(
std::vector<std::pair<std::string, std::string>> metaData)
{
#ifdef DEBUG
std::cout << "Phobos_Layer::setMetaData" << std::endl;
#endif
std::for_each(metaData.begin(), metaData.end(),
[&](std::pair<std::string, std::string> pair){
int rc = pho_attr_set(&descriptor.xd_attrs, pair.first.c_str(),
pair.second.c_str());
if(rc)
{
std::for_each(
metaData.begin(), metaData.end(),
[&](std::pair<std::string, std::string> pair) {
int rc = pho_attr_set(
&descriptor.xd_attrs, pair.first.c_str(), pair.second.c_str());
if (rc) {
throw fiphoexceptions::PhobosException("pho_attr_set", rc);
}
});
......@@ -55,29 +54,32 @@ void FiPhobo::startPutOperation(unsigned int size, std::string objectID)
#endif
startFIFO();
char *unconstedObjectID = new char[objectID.length() + 1];
char* unconstedObjectID = new char[objectID.length() + 1];
strcpy(unconstedObjectID, objectID.c_str());
descriptor.xd_op = PHO_XFER_OP_PUT;
descriptor.xd_op = PHO_XFER_OP_PUT;
descriptor.xd_objid = unconstedObjectID;
descriptor.xd_fd = fifo_descriptor;
descriptor.xd_size = size;
descriptor.xd_fd = fifo_descriptor;
descriptor.xd_size = size;
#ifdef DEBUG
std::cout << "Starting async phobos_put_cpp" << std::endl;
#endif
phobos_result = std::async([&](){
std::cout << "Phobos Thread id " << std::this_thread::get_id() << std::endl;
phobos_result = std::async([&]() {
std::cout << "Phobos Thread id " << std::this_thread::get_id()
<< std::endl;
return phobos_put_cpp(&descriptor, 1, NULL, NULL);
});
std::cout << "Main Thread id " << std::this_thread::get_id() << std::endl;
//TODOOOO
// TODOOOO
// delete [] unconstedObjectID;
}
static long int fifoWriteTemp(std::unique_ptr<folly::IOBuf> buffer, int fifo_descriptor){
static long int fifoWriteTemp(
std::unique_ptr<folly::IOBuf> buffer, int fifo_descriptor)
{
std::cout << "IO Thread id " << std::this_thread::get_id() << std::endl;
return write(fifo_descriptor, buffer->data(), buffer->length());
}
......@@ -87,43 +89,39 @@ void FiPhobo::addDataToFIFO(std::unique_ptr<folly::IOBuf> buffer)
#ifdef DEBUG
std::cout << "Phobos_Layer::addDataToFIFO" << std::endl;
#endif
if(putRunning)
{
if (putRunning) {
int ioRC = put_result.get();
if(ioRC < 0)
{
if (ioRC < 0) {
throw fiphoexceptions::FIFOException("write", ioRC);
}
}
putRunning = true;
if(buffer)
{
put_result = std::async([fd = fifo_descriptor, buffer = std::move(buffer)]{
return write(fd, buffer->data(), buffer->length());
});
if (buffer) {
put_result =
std::async([fd = fifo_descriptor, buffer = std::move(buffer)] {
return write(fd, buffer->data(), buffer->length());
});
// io_result.wait();
}
}
void FiPhobo::finishPUT()
{
#ifdef DEBUG
std::cout << "Phobos_Layer::finishPUT" << std::endl;
#endif
int ioRC = put_result.get();
if(ioRC < 0)
{
if (ioRC < 0) {
throw fiphoexceptions::FIFOException("write", ioRC);
}
int phobosRC = phobos_result.get();
if(phobosRC)
{
if (phobosRC) {
throw fiphoexceptions::PhobosException("pho_put", phobosRC);
}
putRunning = false;
}
......@@ -134,16 +132,18 @@ void FiPhobo::startGetOperation(std::string objectID)
#endif
startFIFO();
char *unconstedObjectID = new char[objectID.length() + 1];
char* unconstedObjectID = new char[objectID.length() + 1];
strcpy(unconstedObjectID, objectID.c_str());
descriptor.xd_op = PHO_XFER_OP_GET;
descriptor.xd_op = PHO_XFER_OP_GET;
descriptor.xd_objid = unconstedObjectID;
descriptor.xd_fd = fifo_descriptor;
descriptor.xd_fd = fifo_descriptor;
phobos_result = std::async([&](){
return phobos_get_cpp(&descriptor, 1, NULL, NULL);
});
#ifdef DEBUG
std::cout << "Starting async phobos_get_cpp" << std::endl;
#endif
hobos_result = std::async(
[&]() { return phobos_get_cpp(&descriptor, 1, NULL, NULL); });
}
std::unique_ptr<folly::IOBuf> FiPhobo::getDataFromFIFO(size_t size)
......@@ -151,34 +151,31 @@ std::unique_ptr<folly::IOBuf> FiPhobo::getDataFromFIFO(size_t size)
#ifdef DEBUG
std::cout << "Phobos_Layer::getDataFromFIFO" << std::endl;
#endif
get_result = std::async([&]{
get_result = std::async([&] {
std::unique_ptr<folly::IOBuf> buffer = folly::IOBuf::create(size);
int readRC = read(fifo_descriptor, buffer->writableData(), size);
if(readRC < 0)
{
if (readRC < 0) {
throw fiphoexceptions::FIFOException("read", readRC);
}
return std::move(buffer);
});
int phobosRC = phobos_result.get();
if(phobosRC)
{
if (phobosRC) {
throw fiphoexceptions::PhobosException("pho_get", phobosRC);
}
std::unique_ptr<folly::IOBuf> buffer;
try
{
try {
buffer = std::move(get_result.get());
}
//TODO: Does this make any sense or is it ok if I don't catch this here but
// TODO: Does this make any sense or is it ok if I don't catch this here but
// let the caller catch it - what he has to do anyway?
catch(fiphoexceptions::FIFOException & fifoException){
catch (fiphoexceptions::FIFOException& fifoException) {
throw fifoException;
}
return std::move(buffer);
}
......@@ -187,44 +184,40 @@ FiPhobo::~FiPhobo()
#ifdef DEBUG
std::cout << "Phobos_Layer::~Phobos_Layer" << std::endl;
#endif
// pho_attrs_free(&descriptor.xd_attrs); // TODO: Is that done in desc_destroy??
pho_xfer_desc_destroy_cpp(&descriptor);
if(fifo_descriptor > 0)
{
close(fifo_descriptor);
// pho_attrs_free(&descriptor.xd_attrs); // TODO: Is that done in
// desc_destroy??
pho_xfer_desc_destroy_cpp(&descriptor);
if (fifo_descriptor > 0) {
close(fifo_descriptor);
}
if( access( fifoName.c_str(), F_OK ) != -1 )
{
if (access(fifoName.c_str(), F_OK) != -1) {
remove(fifoName.c_str());
}
}
void FiPhobo::startFIFO()
{
#ifdef DEBUG
std::cout << "Phobos_Layer::startFIFO" << std::endl;
#endif
int rc = mkfifo(fifoName.c_str(), 0777);
if(rc < 0)
{
if(errno != EEXIST)
{
if (rc < 0) {
if (errno != EEXIST) {
throw fiphoexceptions::FIFOException("mkfifo", errno);
return;
}
}
fifo_descriptor = open(fifoName.c_str(), O_RDWR);
if (fifo_descriptor < 0)
{
if (fifo_descriptor < 0) {
std::stringstream ss;
ss <<"open with filename " << fifoName.c_str();
ss << "open with filename " << fifoName.c_str();
throw fiphoexceptions::FIFOException(ss.str(), errno);
return;
}
#ifdef DEBUG
std::cout << "End of Phobos_Layer::startFIFO" << std::endl;
#endif
}
} // namespace fiphoboserver
} // namespace fiphoboserver
......@@ -11,40 +11,40 @@ extern "C" {
namespace fiphoboserver {
// TODO: Remember the m-versions: PUT and GET functions can work on more than one
// file. Then this structure is stupid. Maybe with a vector of descriptors?
class FiPhobo
{
public:
// TODO: Remember the m-versions: PUT and GET functions can work on more than
// one file. Then this structure is stupid. Maybe with a vector of descriptors?
class FiPhobo {
public:
FiPhobo();
void setBucketName(std::string bucketName);
void setMetaData(std::vector<std::pair<std::string, std::string>> metaData);
void startPutOperation(unsigned int size, std::string objectID);
void addDataToFIFO(std::unique_ptr<folly::IOBuf> buffer);
void finishPUT();
void startGetOperation(std::string objectID);
std::unique_ptr<folly::IOBuf> getDataFromFIFO(size_t size);
void finishGET();
~FiPhobo();
private:
private:
void startFIFO();
struct pho_xfer_desc descriptor = {0};
std::string fifoName = "/tmp/fiphoboserver_fifotemp";
int fifo_descriptor = -1;
std::string fifoName = "/tmp/fiphoboserver_fifotemp";
int fifo_descriptor = -1;
std::future<int> phobos_result;
std::future<long int> put_result;
std::future<std::unique_ptr<folly::IOBuf> > get_result;
std::future<std::unique_ptr<folly::IOBuf>> get_result;
bool putRunning = false;
};
} // namespace fiphoboserver
} // namespace fiphoboserver
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment