Commit 0a9e67a8 authored by Michael Davis's avatar Michael Davis
Browse files

Adds auto-generated Protobuf3 headers

parent 3f6f783a
CPPFLAGS=-I/usr/include/xrootd -fPIC -std=c++11
LDFLAGS=-lXrdSsi-4 -lXrdSsiLib
CPPFLAGS=-I/usr/include/xrootd -I/usr/include/protobuf3 -fPIC -std=c++1y -pedantic -Wall -Wextra -Werror -Wno-unused-parameter
LDFLAGS=-L/usr/lib64/protobuf3 -lXrdSsi-4 -lXrdSsiLib
LINK.o=$(LINK.cc)
all: test_client frontend_ssi.so
test_client: test_client.o
test_client.o: test_client.cpp TestSsiService.h
# XrdSsi server plugin
frontend_ssi.so: frontend_ssi.o
$(LINK.cc) -shared $^ $(LOADLIBES) $(LDLIBS) -o $@
# XrdSsi test client
all: test_client
LDLIBS=-lprotobuf
test_client: test_client.o test.pb.o
test_client.o: test_client.cpp TestSsiService.h test.pb.h
test.pb.h: test.proto
#protoc3 --cpp_out=. --plugin=protoc-gen-XrdSsi=./protoc-gen-XrdSsi --XrdSsi_out=. test.proto
protoc3 --cpp_out=. test.proto
# Protobuf3 plugin (to parse services in .proto file)
LDLIBS=-lprotobuf -lprotoc
protoc-gen-XrdSsi: protoc-gen-XrdSsi.cpp
clean:
rm -f frontend_ssi.o frontend_ssi.so
rm -f frontend_ssi.o frontend_ssi.so test_client test_client.o
#ifndef __TEST_SSI_PROTOBUF_H
#define __TEST_SSI_PROTOBUF_H
#include <google/protobuf/util/json_util.h>
#include "test.pb.h"
namespace xrdssi {
namespace test {
inline std::string MessageToJsonString(const google::protobuf::Message &message)
{
using namespace google::protobuf::util;
std::string output;
JsonPrintOptions options;
options.add_whitespace = true;
options.always_print_primitive_fields = true;
MessageToJsonString(message, &output, options); // returns util::Status
return output;
}
} // test
} // xrdssi
#endif
#ifndef __TEST_SSI_SERVICE_H
#define __TEST_SSI_SERVICE_H
#include <iostream>
#include <stdexcept>
#include "XrdSsi/XrdSsiProvider.hh"
#include "XrdSsi/XrdSsiService.hh"
// Probably we want to allow multiple resources, e.g. streaming and non-streaming versions of the service
// Can this be defined in the protobuf definition?
const std::string TestSsiResource("/test");
// Class to convert a XRootD error into a std::exception
class XrdSsiException : public std::exception
{
public:
XrdSsiException(const XrdSsiErrInfo &eInfo) : error_msg(eInfo.Get()) {}
const char* what() const noexcept { return error_msg.c_str(); }
private:
std::string error_msg;
};
// XrdSsiProviderClient is instantiated and managed by the SSI library
extern XrdSsiProvider *XrdSsiProviderClient;
class TestSsiService
{
public:
TestSsiService() = delete;
TestSsiService(std::string hostname, int port) : resource(TestSsiResource)
{
XrdSsiErrInfo eInfo;
if(!(serverP = XrdSsiProviderClient->GetService(eInfo, hostname + ":" + std::to_string(port))))
{
throw XrdSsiException(eInfo);
}
}
~TestSsiService()
{
// The XrdSsiService object cannot be explicitly deleted. The Stop() method deletes the object if
// it is safe to do so. A service object can only be deleted after all requests handed to the object
// have completed, i.e. Finished() has been called on each request.
if(serverP->Stop())
{
std::cerr << "Stopped SSI service" << std::endl;
}
else
{
std::cerr << "Failed to stop SSI service" << std::endl;
// Unpalatable choice here between passing back control to the calling scope with a possible memory leak,
// or trying to force all requests to Finish with possible blocking behaviour...
}
}
private:
const XrdSsiResource resource; // Requests are bound to this resource
XrdSsiService *serverP; // Pointer to XRootD Server object
};
#endif
......@@ -33,8 +33,8 @@ void Execute()
cerr << "Execute()" << endl;
int reqLen;
char *reqData = GetRequest(reqLen);
//int reqLen;
//char *reqData = GetRequest(reqLen);
// Parse the request
......
syntax = "proto3";
option cc_generic_services = false; //< Generic services are deprecated
package eos.wfe;
package xrdssi.test;
// XRootD SSI Request
......
#include <unistd.h> // for sleep
#include "TestSsiService.h"
#include "TestSsiProtobuf.h"
int main(int argc, char *argv[])
{
// Verify that the version of the Google Protocol Buffer library that we linked against is
// compatible with the version of the headers we compiled against
GOOGLE_PROTOBUF_VERIFY_VERSION;
// Obtain a Service Provider
const std::string host = "localhost";
......@@ -12,13 +18,18 @@ int main(int argc, char *argv[])
try
{
TestSsiService test_ssi_service(host, port);
}
catch (std::exception& e)
{
std::cerr << "TestSsiService() failed with error: " << e.what() << std::endl;
return 1;
}
// Create a Request object
xrdssi::test::Request request;
request.set_message_text("Archive some file");
// Output message in Json format
std::cout << "Sending message:" << std::endl;
std::cout << xrdssi::test::MessageToJsonString(request);
// Initiate a Request
......@@ -45,17 +56,28 @@ int main(int argc, char *argv[])
// Note: it is safe to delete the XrdSsiResource object after ProcessRequest() returns.
#endif
// Wait for the response callback
// Wait for the response callback
std::cout << "Request sent, going to sleep..." << std::endl;
std::cout << "Request sent, going to sleep..." << std::endl;
int wait_secs = 40;
int wait_secs = 40;
while(--wait_secs)
while(--wait_secs)
{
std::cerr << ".";
sleep(1);
}
std::cout << "All done, exiting." << std::endl;
}
catch (std::exception& e)
{
std::cerr << ".";
sleep(1);
std::cerr << "TestSsiService failed with error: " << e.what() << std::endl;
return 1;
}
std::cout << "All done, exiting." << std::endl;
// Optional: Delete all global objects allocated by libprotobuf
google::protobuf::ShutdownProtobufLibrary();
}
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