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

Ran clang format

parent 29bfd8de
#pragma once
#include <string>
#include <sstream>
#include <string>
namespace fiphoexceptions {
namespace fiphoexceptions{
class PhobosException : std::exception
{
public:
PhobosException(std::string callingPhobosFunction, int rc) :
function(callingPhobosFunction),
class PhobosException : std::exception {
public:
PhobosException(std::string callingPhobosFunction, int rc) :
function(callingPhobosFunction),
rc(rc)
{}
const char* what() const noexcept override
{
}
const char* what() const noexcept override
{
std::stringstream ss;
ss <<"Phobos had an error in function " << function << ": " << std::strerror(rc);
ss << "Phobos had an error in function " << function << ": "
<< std::strerror(rc);
return ss.str().c_str();
}
private:
private:
int rc;
std::string function;
};
class FIFOException : std::exception
{
public:
FIFOException(std::string caller, int value) :
caller(caller),
value(value)
{}
class FIFOException : std::exception {
public:
FIFOException(std::string caller, int value) : caller(caller), value(value)
{
}
const char* what() const noexcept override
{
std::stringstream ss;
ss <<"FIFO IO had an error in function " << caller << ": " << std::strerror(errno);
ss << "FIFO IO had an error in function " << caller << ": "
<< std::strerror(errno);
return ss.str().c_str();
}
private:
private:
int value;
std::string caller;
};
}
\ No newline at end of file
} // namespace fiphoexceptions
#include "fiphobo_blocking.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>
namespace fiphoboserver
{
namespace fiphoboserver {
FiPhobo::FiPhobo()
{
......@@ -24,24 +23,24 @@ 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) {
printf("pho_attr_set returned an error: %d\n", rc);
return;
}
}
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) {
printf("pho_attr_set returned an error: %d\n", rc);
return;
}
......@@ -55,22 +54,22 @@ void FiPhobo::startPutOperation(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;
// #ifdef DEBUG
// std::cout << "Starting async phobos_put_cpp" << std::endl;
// #endif
// phobos_result = std::async([&](){
// return phobos_put_cpp(&descriptor, 1, NULL, NULL);
// });
//
//TODOOOO
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([&](){
// return phobos_put_cpp(&descriptor, 1, NULL, NULL);
// });
//
// TODOOOO
// delete [] unconstedObjectID;
}
......@@ -88,12 +87,12 @@ void FiPhobo::addDataToFIFO(std::unique_ptr<folly::IOBuf> buffer)
// }
// }
// ioRunning = true;
//
//
// buffer->coalesce();
// io_result = std::async([&](){
// return write(fifo_descriptor, buffer->data(), buffer->length());
// });
size_t written = write(fifo_descriptor, buffer->data(), buffer->length());
}
......@@ -104,12 +103,12 @@ 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);
......@@ -122,8 +121,8 @@ std::unique_ptr<folly::IOBuf> FiPhobo::getDataFromFIFO(size_t size)
std::cout << "Phobos_Layer::getDataFromFIFO" << std::endl;
#endif
std::unique_ptr<folly::IOBuf> buffer = folly::IOBuf::create(size);
// if(ioRunning)
// {
// int ioRC = io_result.get();
......@@ -133,26 +132,25 @@ std::unique_ptr<folly::IOBuf> FiPhobo::getDataFromFIFO(size_t size)
// }
// }
// ioRunning = true;
//
//
// io_result = std::async([&](){
// buffer->unshare();
// return read(fifo_descriptor, buffer->writableData(), size);
// });
int phobos_return = phobos_get_cpp(&descriptor, 1, NULL, NULL);
if(phobos_return < 0)
{
if (phobos_return < 0) {
std::cout << "GET: schade schade schade " << std::endl;
//error handling
// error handling
}
lseek(fifo_descriptor, 0, SEEK_SET);
buffer->unshare();
read(fifo_descriptor, buffer->writableData(), size);
return std::move(buffer);
}
void FiPhobo::finishIO()
{
#ifdef DEBUG
......@@ -163,24 +161,22 @@ void FiPhobo::finishIO()
// {
// //TODO error handling
// }
//
//
// int phobosRC = phobos_result.get();
// if(phobosRC)
// {
// //TODO error handling!
// }
// ioRunning = false;
if(descriptor.xd_op == PHO_XFER_OP_PUT)
{
if (descriptor.xd_op == PHO_XFER_OP_PUT) {
lseek(fifo_descriptor, 0, SEEK_SET);
int phobos_return = phobos_put_cpp(&descriptor, 1, NULL, NULL);
if(phobos_return < 0)
{
if (phobos_return < 0) {
std::cout << "PUT: schade schade schade " << std::endl;
//error handling
// error handling
}
}
}
......@@ -190,18 +186,18 @@ 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 )
// {
// remove(fifoName.c_str());
// }
}
void FiPhobo::startFIFO()
{
#ifdef DEBUG
......@@ -213,12 +209,11 @@ void FiPhobo::startFIFO()
// printf("mkfifo returned an error: %s\n", std::strerror(errno));
// return;
// }
fifo_descriptor = open(fifoName.c_str(), O_RDWR);
if (fifo_descriptor < 0)
{
if (fifo_descriptor < 0) {
printf("Could not open file: %s\n", fifoName);
return;
}
}
} // namespace fiphoboserver
} // namespace fiphoboserver
......@@ -11,39 +11,37 @@ 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(int size, std::string objectID);
void addDataToFIFO(std::unique_ptr<folly::IOBuf> buffer);
void startGetOperation(std::string& objectID);
std::unique_ptr<folly::IOBuf> getDataFromFIFO(size_t size);
void finishIO();
~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> io_result;
bool ioRunning = false;
};
} // namespace fiphoboserver
} // namespace fiphoboserver
#include "phobos_store.h"
int phobos_put_cpp(struct pho_xfer_desc *xfers, size_t n,
pho_completion_cb_t cb, void *udata)
int phobos_put_cpp(
struct pho_xfer_desc* xfers, size_t n, pho_completion_cb_t cb, void* udata)
{
return phobos_put(xfers, n, cb, udata);
}
int phobos_get_cpp(struct pho_xfer_desc *xfers, size_t n,
pho_completion_cb_t cb, void *udata)
int phobos_get_cpp(
struct pho_xfer_desc* xfers, size_t n, pho_completion_cb_t cb, void* udata)
{
return phobos_get(xfers, n, cb, udata);
}
int phobos_getmd_cpp(struct pho_xfer_desc *xfers, size_t n,
pho_completion_cb_t cb, void *udata)
{
return phobos_getmd(xfers, n, cb, udata);
int phobos_getmd_cpp(
struct pho_xfer_desc* xfers, size_t n, pho_completion_cb_t cb, void* udata)
{
return phobos_getmd(xfers, n, cb, udata);
}
void pho_xfer_desc_destroy_cpp(struct pho_xfer_desc *xfer)
void pho_xfer_desc_destroy_cpp(struct pho_xfer_desc* xfer)
{
return pho_xfer_desc_destroy(xfer);
}
\ No newline at end of file
}
......@@ -13,21 +13,21 @@
enum pho_xfer_flags {
/* put: replace the object if it already exists (_not supported_)
* get: replace the target file if it already exists */
PHO_XFER_OBJ_REPLACE = (1 << 0),
PHO_XFER_OBJ_REPLACE = (1 << 0),
};
enum pho_xfer_op {
PHO_XFER_OP_PUT, /**< Put operation */
PHO_XFER_OP_GET, /**< Get operation */
PHO_XFER_OP_GETMD /**< Get metadata operation */
PHO_XFER_OP_PUT, /**< Put operation */
PHO_XFER_OP_GET, /**< Get operation */
PHO_XFER_OP_GETMD /**< Get metadata operation */
};
/**
* A simple array of tags (strings)
*/
struct tags {
char **tags; /**< The array of tags */
size_t n_tags; /**< Number of tags */
char** tags; /**< The array of tags */
size_t n_tags; /**< Number of tags */
};
......@@ -40,25 +40,25 @@ struct tags {
* - phobos_put()
*/
struct pho_xfer_desc {
char *xd_objid; /**< Object id to read or write */
enum pho_xfer_op xd_op; /**< Operation to perform
* (GET, GETMD or PUT)
*/
int xd_fd; /**< positive fd if xd_id_open */
ssize_t xd_size; /**< Amount of data to write (for the GET
* operation, the size read is equal to
* the size of the retrieved object)
*/
const char *xd_layout_name; /**< Name of the layout module to use
* (for put).
*/
struct pho_attrs xd_attrs; /**< User defined attribute to get / put */
enum pho_xfer_flags xd_flags; /**< See enum pho_xfer_flags doc */
struct tags xd_tags; /**< Tags to select a media to write */
int xd_rc; /**< Outcome of this xfer */
char* xd_objid; /**< Object id to read or write */
enum pho_xfer_op xd_op; /**< Operation to perform
* (GET, GETMD or PUT)
*/
int xd_fd; /**< positive fd if xd_id_open */
ssize_t xd_size; /**< Amount of data to write (for the GET
* operation, the size read is equal to
* the size of the retrieved object)
*/
const char* xd_layout_name; /**< Name of the layout module to use
* (for put).
*/
struct pho_attrs xd_attrs; /**< User defined attribute to get / put */
enum pho_xfer_flags xd_flags; /**< See enum pho_xfer_flags doc */
struct tags xd_tags; /**< Tags to select a media to write */
int xd_rc; /**< Outcome of this xfer */
};
typedef void (*pho_completion_cb_t)(void *u, const struct pho_xfer_desc *, int);
typedef void (*pho_completion_cb_t)(void* u, const struct pho_xfer_desc*, int);
/**
......@@ -78,8 +78,8 @@ typedef void (*pho_completion_cb_t)(void *u, const struct pho_xfer_desc *, int);
* This function returns the first encountered error or 0 if all
* sub-operations have succeeded.
*/
int phobos_put_cpp(struct pho_xfer_desc *xfers, size_t n,
pho_completion_cb_t cb, void *udata);
int phobos_put_cpp(
struct pho_xfer_desc* xfers, size_t n, pho_completion_cb_t cb, void* udata);
/**
* Retrieve N files from the object store
......@@ -94,8 +94,8 @@ int phobos_put_cpp(struct pho_xfer_desc *xfers, size_t n,
* This function returns the first encountered error or 0 if all
* sub-operations have succeeded.
*/
int phobos_get_cpp(struct pho_xfer_desc *xfers, size_t n,
pho_completion_cb_t cb, void *udata);
int phobos_get_cpp(
struct pho_xfer_desc* xfers, size_t n, pho_completion_cb_t cb, void* udata);
/**
* Retrieve N file metadata from the object store
......@@ -109,8 +109,8 @@ int phobos_get_cpp(struct pho_xfer_desc *xfers, size_t n,
* This function returns the first encountered error of 0 if all
* sub-operations have succeeded.
*/
int phobos_getmd_cpp(struct pho_xfer_desc *xfers, size_t n,
pho_completion_cb_t cb, void *udata);
int phobos_getmd_cpp(
struct pho_xfer_desc* xfers, size_t n, pho_completion_cb_t cb, void* udata);
/** query metadata of the object store */
/* TODO int phobos_query(criteria, &obj_list); */
......@@ -120,6 +120,6 @@ int phobos_getmd_cpp(struct pho_xfer_desc *xfers, size_t n,
* Free tags and attributes resources associated with this xfer,
* as they are allocated in phobos.
*/
void pho_xfer_desc_destroy_cpp(struct pho_xfer_desc *xfer);
void pho_xfer_desc_destroy_cpp(struct pho_xfer_desc* xfer);
#endif
\ No newline at end of file
#endif
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