Skip to content
Snippets Groups Projects
Commit 5f5db5f4 authored by Michael Davis's avatar Michael Davis
Browse files

Sends Metadata from server

parent 6c9ca6b4
Branches
Tags
No related merge requests found
...@@ -60,22 +60,20 @@ public: ...@@ -60,22 +60,20 @@ public:
} }
} }
void send(RequestType request_msg) void send(RequestType request)
{ {
// Requests are always executed in the context of a service. They need to correspond to what the service allows.
XrdSsiRequest *requestP;
// Serialize the request object // Serialize the request object
std::string request_str; std::string request_str;
if(!request_msg.SerializeToString(&request_str)) if(!request.SerializeToString(&request_str))
{ {
throw XrdSsiException("SerializeToString() failed"); throw XrdSsiException("request.SerializeToString() failed");
} }
requestP = new TestSsiRequest(request_str, timeout); // Requests are always executed in the context of a service. They need to correspond to what the service allows.
XrdSsiRequest *requestP = new TestSsiRequest(request_str, timeout);
// Transfer ownership of the request to the service object // Transfer ownership of the request to the service object
// TestSsiRequest handles deletion of the request buffer, so we can allow the pointer to go out-of-scope // TestSsiRequest handles deletion of the request buffer, so we can allow the pointer to go out-of-scope
......
...@@ -7,7 +7,7 @@ class TestSsiRequest : public XrdSsiRequest ...@@ -7,7 +7,7 @@ class TestSsiRequest : public XrdSsiRequest
{ {
public: public:
TestSsiRequest(const std::string &buffer_str, uint16_t tmo=0) : request_buffer(buffer_str.c_str()), request_len(buffer_str.length()) TestSsiRequest(const std::string &buffer_str, uint16_t tmo=0) : request_buffer(buffer_str.c_str()), request_len(buffer_str.size())
{ {
std::cerr << "Creating TestSsiRequest object, setting tmo=" << tmo << std::endl; std::cerr << "Creating TestSsiRequest object, setting tmo=" << tmo << std::endl;
this->SetTimeOut(tmo); this->SetTimeOut(tmo);
......
...@@ -22,7 +22,7 @@ void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Meta ...@@ -22,7 +22,7 @@ void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Meta
// Output message in Json format (for debugging) // Output message in Json format (for debugging)
std::cerr << "Sending response:" << std::endl; std::cerr << "Preparing response:" << std::endl;
std::cerr << xrdssi::test::MessageToJsonString(response); std::cerr << xrdssi::test::MessageToJsonString(response);
} }
...@@ -35,9 +35,14 @@ void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Meta ...@@ -35,9 +35,14 @@ void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Meta
template <> template <>
void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Metadata, xrdssi::test::Alert>::ExecuteMetadata() void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Metadata, xrdssi::test::Alert>::ExecuteMetadata()
{ {
std::cerr << "Sending metadata..." << std::endl; // Set metadata
const std::string metadata("Have some metadata!");
SetMetadata(metadata.c_str(), metadata.size()); metadata.set_message_text("Have some metadata");
// Output message in Json format (for debugging)
std::cerr << "Preparing metadata..." << std::endl;
std::cerr << xrdssi::test::MessageToJsonString(metadata);
} }
...@@ -63,4 +68,8 @@ void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Meta ...@@ -63,4 +68,8 @@ void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Meta
* A parameter to the method tells you why it’s being called. * A parameter to the method tells you why it’s being called.
* *
* See example p.45 * See example p.45
template <>
void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Metadata, xrdssi::test::Alert>::ExecuteAlert()
{
}
*/ */
...@@ -37,6 +37,8 @@ private: ...@@ -37,6 +37,8 @@ private:
RequestType request; RequestType request;
ResponseType response; ResponseType response;
MetadataType metadata;
AlertType alert;
}; };
...@@ -61,7 +63,7 @@ void RequestProc<RequestType, ResponseType, MetadataType, AlertType>::Execute() ...@@ -61,7 +63,7 @@ void RequestProc<RequestType, ResponseType, MetadataType, AlertType>::Execute()
if(!request.ParseFromString(request_str)) if(!request.ParseFromString(request_str))
{ {
throw XrdSsiException("ParseFromString() failed"); throw XrdSsiException("request.ParseFromString() failed");
} }
// Release the request buffer (optional, perhaps it is more efficient to reuse it?) // Release the request buffer (optional, perhaps it is more efficient to reuse it?)
...@@ -76,22 +78,39 @@ void RequestProc<RequestType, ResponseType, MetadataType, AlertType>::Execute() ...@@ -76,22 +78,39 @@ void RequestProc<RequestType, ResponseType, MetadataType, AlertType>::Execute()
ExecuteAlerts(); ExecuteAlerts();
// Optional: send metadata ahead of the response // Optional: prepare to send metadata ahead of the response
ExecuteMetadata(); ExecuteMetadata();
// Serialize the Response // Serialize the Metadata
std::string response_str; std::string response_str;
if(!metadata.SerializeToString(&response_str))
{
throw XrdSsiException("metadata.SerializeToString() failed");
}
// Send the Metadata
if(response_str.size() > 0)
{
SetMetadata(response_str.c_str(), response_str.size());
}
// Serialize the Response
if(!response.SerializeToString(&response_str)) if(!response.SerializeToString(&response_str))
{ {
throw XrdSsiException("SerializeToString() failed"); throw XrdSsiException("response.SerializeToString() failed");
} }
// Send the response // Send the response
SetResponse(response_str.c_str(), response_str.length()); if(response_str.size() > 0)
{
SetResponse(response_str.c_str(), response_str.size());
}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment