[Cppfcplib] r13513 - trunk/apps/CppFCPLib

mkolar at freenetproject.org mkolar at freenetproject.org
Mon Jun 11 09:52:17 UTC 2007


Author: mkolar
Date: 2007-06-11 09:52:17 +0000 (Mon, 11 Jun 2007)
New Revision: 13513

Added:
   trunk/apps/CppFCPLib/FCPListPeersResult.cpp
   trunk/apps/CppFCPLib/FCPListPeersResult.h
   trunk/apps/CppFCPLib/FCPResult.cpp
   trunk/apps/CppFCPLib/FCPResult.h
   trunk/apps/CppFCPLib/PeerMessage.h
   trunk/apps/CppFCPLib/ServerMessage.cpp
   trunk/apps/CppFCPLib/ServerMessage.h
Removed:
   trunk/apps/CppFCPLib/JobTicket.cpp
Modified:
   trunk/apps/CppFCPLib/JobTicket.h
   trunk/apps/CppFCPLib/Message.cpp
   trunk/apps/CppFCPLib/Message.h
   trunk/apps/CppFCPLib/Node.cpp
   trunk/apps/CppFCPLib/Node.h
   trunk/apps/CppFCPLib/NodeThread.cpp
   trunk/apps/CppFCPLib/NodeThread.h
Log:
* initial creation of a hierarchy for messages
* initial creation of a hierarchy for results



Added: trunk/apps/CppFCPLib/FCPListPeersResult.cpp
===================================================================
--- trunk/apps/CppFCPLib/FCPListPeersResult.cpp	                        (rev 0)
+++ trunk/apps/CppFCPLib/FCPListPeersResult.cpp	2007-06-11 09:52:17 UTC (rev 13513)
@@ -0,0 +1,14 @@
+#include "FCPListPeersResult.h"
+
+
+using namespace FCPLib;
+
+FCPListPeersResult::FCPResultPtr
+FCPListPeersResult::createFromMessages(const std::vector<ServerMessage::ServerMessagePtr> &nodeResponse)
+{
+  FCPListPeersResultPtr ret( new FCPListPeersResult() );
+
+  ret->peers = std::vector<ServerMessage::ServerMessagePtr>( nodeResponse );
+
+  return ret;
+}

Added: trunk/apps/CppFCPLib/FCPListPeersResult.h
===================================================================
--- trunk/apps/CppFCPLib/FCPListPeersResult.h	                        (rev 0)
+++ trunk/apps/CppFCPLib/FCPListPeersResult.h	2007-06-11 09:52:17 UTC (rev 13513)
@@ -0,0 +1,25 @@
+#ifndef FCPLISTPEERSRESULT_H__
+#define FCPLISTPEERSRESULT_H__
+
+
+#include <vector>
+#include <memory>
+#include "Message.h"
+#include "FCPResult.h"
+
+
+namespace FCPLib {
+
+
+class FCPListPeersResult : public FCPResult {
+  std::vector<ServerMessage::ServerMessagePtr> peers;
+
+  FCPListPeersResult() {}
+public:
+  typedef boost::shared_ptr<FCPListPeersResult> FCPListPeersResultPtr;
+
+  static FCPResultPtr createFromMessages(const std::vector<ServerMessage::ServerMessagePtr> &nodeResponse);
+};
+}
+
+#endif

Added: trunk/apps/CppFCPLib/FCPResult.cpp
===================================================================
--- trunk/apps/CppFCPLib/FCPResult.cpp	                        (rev 0)
+++ trunk/apps/CppFCPLib/FCPResult.cpp	2007-06-11 09:52:17 UTC (rev 13513)
@@ -0,0 +1,19 @@
+#include "FCPResult.h"
+#include <stdexcept>
+
+
+#include "FCPListPeersResult.h"
+
+using namespace FCPLib;
+
+FCPResult::FCPResultPtr
+FCPResult::factory(const std::string cmd, std::vector<ServerMessage::ServerMessagePtr> nodeResponse)
+{
+  if (cmd == "ListPeers") {
+    return FCPListPeersResult::createFromMessages( nodeResponse );
+  }
+
+  throw new std::runtime_error("Not implemented : " + cmd);
+}
+
+FCPResult::~FCPResult() {}

Added: trunk/apps/CppFCPLib/FCPResult.h
===================================================================
--- trunk/apps/CppFCPLib/FCPResult.h	                        (rev 0)
+++ trunk/apps/CppFCPLib/FCPResult.h	2007-06-11 09:52:17 UTC (rev 13513)
@@ -0,0 +1,22 @@
+#ifndef FCPRESULT_H__
+#define FCPRESULT_H__
+
+#include "ServerMessage.h"
+
+#include <boost/shared_ptr.hpp>
+#include <vector>
+#include <string>
+
+namespace FCPLib {
+
+class FCPResult {
+public:
+  typedef boost::shared_ptr<FCPResult> FCPResultPtr;
+
+  static FCPResultPtr factory(const std::string cmd, std::vector<ServerMessage::ServerMessagePtr> nodeResponse);
+  virtual ~FCPResult() = 0;
+};
+
+}
+
+#endif

Deleted: trunk/apps/CppFCPLib/JobTicket.cpp
===================================================================
--- trunk/apps/CppFCPLib/JobTicket.cpp	2007-06-10 21:46:45 UTC (rev 13512)
+++ trunk/apps/CppFCPLib/JobTicket.cpp	2007-06-11 09:52:17 UTC (rev 13513)
@@ -1,125 +0,0 @@
-
-#include "JobTicket.h"
-#include "DefaultValues.h"
-#include "zthread/Thread.h"
-#include <boost/lexical_cast.hpp>
-
-using namespace FCPLib;
-
-JobTicket::JobTicket(std::string id_, Message::MessagePtr &cmd_)
-  : id(id_),
-    cmd(cmd_),
-    async_(false),
-    keep(false),
-    waitTillSent_(false),
-    timeout_(oneyear),
-    isReprValid(false)
-//    hasStream(false)
-{
-  lock.acquire();
-  reqSentLock.acquire();
-}
-
-JobTicket&
-JobTicket::async(bool async)
-{
-  isReprValid = false;
-  async_ = async; return *this;
-}
-
-inline JobTicket&
-JobTicket::keepJob(bool keep_)
-{
-  isReprValid = false;
-  keep = keep_; return *this;
-}
-inline  JobTicket&
-JobTicket::waitTillSent(bool wait_)
-{
-  isReprValid = false;
-  waitTillSent_ = wait_; return *this;
-}
-inline  JobTicket&
-JobTicket::timeout(int timeout)
-{
-  isReprValid = false;
-  timeout_ = timeout; return *this;
-}
-
-const std::string&
-JobTicket::getId() const
-{
-  return id;
-}
-
-const std::string&
-JobTicket::commandName() const
-{
-  return cmd->getHeader();
-}
-
-const std::string&
-JobTicket::getMessageText() const
-{
-  return cmd->toString();
-}
-
-void
-JobTicket::wait(unsigned int timeout)
-{
-  if (!timeout){
-    while (!lock.tryAcquire(100))
-      ZThread::Thread::sleep(100);
-    lock.release();
-    return;
-  }
-
-  unsigned int then = (unsigned int) time(0);
-  unsigned int elapsed;
-  while (!reqSentLock.tryAcquire(100)){
-    elapsed = (unsigned int) time(0) - then;
-    if (elapsed < timeout){
-                   Thread::sleep(1000)
-      log().log(DEBUG, "wait:"+job->commandName()+":"+job->getId()+": job not dispatched, timeout in " +
-        boost::lexical_cast<std::string>(timeout-elapsed));
-      continue;
-    }
-  }
-}
-
-void
-JobTicket::waitTillReqSent()
-{
-  reqSentLock.acquire();
-}
-
-void
-JobTicket::putResult()
-{
-  lock.release();
-}
-
-const std::vector<Message::MessagePtr>&
-JobTicket::getResponse() const
-{
-  return nodeResponse;
-}
-
-const std::string&
-JobTicket::toString()
-{
-  if (isReprValid)
-    return repr;
-
-  repr = "";
-  isReprValid = true;
-
-  repr += "Job id=" + id + "\n";
-  repr += getMessageText();
-  repr += "async=" + boost::lexical_cast<std::string>(async_) + "\n";
-  repr += "keepJob=" + boost::lexical_cast<std::string>(keep) + "\n";
-  repr += "waitTillSent=" + boost::lexical_cast<std::string>(waitTillSent_) + "\n";
-  repr += "timeout=" + boost::lexical_cast<std::string>(timeout_) + "\n";
-
-  return repr;
-}

Modified: trunk/apps/CppFCPLib/JobTicket.h
===================================================================
--- trunk/apps/CppFCPLib/JobTicket.h	2007-06-10 21:46:45 UTC (rev 13512)
+++ trunk/apps/CppFCPLib/JobTicket.h	2007-06-11 09:52:17 UTC (rev 13513)
@@ -1,29 +1,40 @@
 #ifndef JOBTICKET_H__
 #define JOBTICKET_H__
 
-#include "Log.h"
 #include "Message.h"
+#include "ServerMessage.h"
+#include "FCPResult.h"
+
+#include <stdexcept>
 #include <vector>
+#include <iostream>
+
 #include <boost/shared_ptr.hpp>
-#include <iostream>
+
 #include "zthread/FastMutex.h"
 
 namespace FCPLib {
 
 class NodeThread;
 
+
 class JobTicket {
   std::string id;
   Message::MessagePtr cmd;
-  std::vector<Message::MessagePtr> nodeResponse;
-  bool async_;
+
+  std::vector<ServerMessage::ServerMessagePtr> nodeResponse;
+
+  bool async;
   bool keep;
-  bool waitTillSent_;
-  int timeout_;
+  bool waitTillSent;
+  int timeout;
 
   std::string repr;
   bool isReprValid;
 
+  FCPResult::FCPResultPtr result;
+  bool _hasResult;
+
 //  bool hasStream;
 //  ostream stream;
 
@@ -32,29 +43,39 @@
   int timeQueued;
 
   void putResult();
+
+
+  JobTicket()
+  {
+    _hasResult = false;
+    isReprValid = false;
+  }
 public:
-  typedef boost::shared_ptr<JobTicket> JobTicketPtr;
+  typedef boost::shared_ptr<JobTicket > JobTicketPtr;
 
-  JobTicket(std::string id_, Message::MessagePtr &cmd_);
-  inline JobTicket& async(bool async_);
-  inline JobTicket& keepJob(bool keep_);
-  inline JobTicket& waitTillSent(bool wait);
-  inline JobTicket& timeout(int timeout);
+  static
+  JobTicketPtr factory(std::string id, Message::MessagePtr cmd,
+                             bool async, bool keep, bool waitTillSent,
+                             int timeout);
 
-  const std::string& commandName() const;
+  const std::string& getCommandName() const;
   const std::string& getId() const;
   const std::string& getMessageText() const;
 
   void wait(unsigned int timeout_=0);
   void waitTillReqSent();
 
-  const std::vector<Message::MessagePtr>& getResponse() const;
+  const std::vector<ServerMessage::ServerMessagePtr>& getResponse() const;
   const std::string& toString();
 
+  const FCPResult::FCPResultPtr getResult() const;
+  bool hasResult() const;
 
   friend class NodeThread;
 };
 
+
+
 }
 
 #endif

Modified: trunk/apps/CppFCPLib/Message.cpp
===================================================================
--- trunk/apps/CppFCPLib/Message.cpp	2007-06-10 21:46:45 UTC (rev 13512)
+++ trunk/apps/CppFCPLib/Message.cpp	2007-06-11 09:52:17 UTC (rev 13513)
@@ -1,16 +1,10 @@
 #include "Message.h"
 
 
-using namespace std;
 using namespace FCPLib;
 
-Message::Message() {
-  isDataType = false;
-  isReprValid = false;
-}
-
 Message::MessagePtr
-Message::factory(std::string &header){
+Message::factory(std::string header){
   Message::MessagePtr m( new Message() );
 
   m->header = header;
@@ -18,37 +12,6 @@
   return m;
 }
 
-Message::MessagePtr
-Message::factory(const char *header){
-  std::string hdr(header);
-
-  return factory(hdr);
-}
-
-Message::MessagePtr
-Message::factory(Server &s){
-  Message::MessagePtr m( new Message() );
-  static char line[1000];
-
-  s.readln(line, 1000);
-  line[strlen(line)-1] = 0;
-  m->header = string(line);
-
-  for (;;) {
-    s.readln(line, 1000);
-    line[strlen(line)-1] = 0;
-
-    if (!strcmp(line, "End") || !strcmp(line, "EndMessage"))
-      break;
-
-    char *val = strchr(line, '=');
-    *val++ = 0;
-    m->fields[string(line)] = string(val);
-  }
-
-  return m;
-}
-
 void
 Message::setField(std::string key, std::string value) {
   // TODO: should i check if a message can contain certain field?
@@ -68,15 +31,15 @@
   if (isReprValid)
     return repr;
   repr = header + "\n";
-  for (map<string, string>::iterator it = fields.begin(); it != fields.end(); ++it)
+  for (std::map<std::string, std::string>::iterator it = fields.begin(); it != fields.end(); ++it)
     if (isDataType && it->first == "Data")
       continue;
     else
       repr += it->first + "=" + it->second + "\n";
   if (isDataType) {
     repr += "DataLength=";
-    sprintf(intToString, "%d", fields["Data"].size());
-    repr += string(intToString);
+    sprintf(intToString, "%d", fields["Data"].size());     // FIXME
+    repr += std::string(intToString);
     repr += "\n";
     repr += "Data\n";
     repr += fields["Data"];
@@ -92,3 +55,4 @@
 {
   return header;
 }
+

Modified: trunk/apps/CppFCPLib/Message.h
===================================================================
--- trunk/apps/CppFCPLib/Message.h	2007-06-10 21:46:45 UTC (rev 13512)
+++ trunk/apps/CppFCPLib/Message.h	2007-06-11 09:52:17 UTC (rev 13513)
@@ -6,7 +6,6 @@
 #include <string>
 #include <map>
 #include <boost/shared_ptr.hpp>
-#include "Server.h"
 
 namespace FCPLib {
 
@@ -16,16 +15,19 @@
 
   std::map<std::string, std::string> fields;
 
+  bool isReprValid;
   bool isDataType;
-  bool isReprValid;
 
-  Message();
+  Message() :
+    isReprValid(false),
+    isDataType(false)
+  {}
+
 public:
   typedef boost::shared_ptr<Message> MessagePtr;
-  static MessagePtr factory(std::string &header);
-  static MessagePtr factory(const char *header);
-  static MessagePtr factory(Server &s);
 
+  static Message::MessagePtr factory(std::string header);
+
   void setField(std::string key, std::string value);
   inline std::string getField(const std::string &key);
   const std::string& getHeader() const;
@@ -33,6 +35,7 @@
   const std::string& toString();
 };
 
+
 }
 
 #endif

Modified: trunk/apps/CppFCPLib/Node.cpp
===================================================================
--- trunk/apps/CppFCPLib/Node.cpp	2007-06-10 21:46:45 UTC (rev 13512)
+++ trunk/apps/CppFCPLib/Node.cpp	2007-06-11 09:52:17 UTC (rev 13513)
@@ -1,6 +1,5 @@
 
 #include "Node.h"
-#include "Message.h"
 #include "Log.h"
 
 using namespace FCPLib;
@@ -23,22 +22,36 @@
   nodeThread = new NodeThread(host, port, clientReqQueue);
   executor.execute( nodeThread );
 
-  Message::MessagePtr m = Message::factory("ClientHello");
+  Message::MessagePtr m = Message::factory(std::string("ClientHello"));
   m->setField("Name", name);
   m->setField("ExpectedVersion", "2.0");
 
   log().log(DEBUG, "Creating ClientHello\n");
-  JobTicket::JobTicketPtr job( new JobTicket("__hello", m) );
+  JobTicket::JobTicketPtr job = JobTicket::factory("__hello", m, false, false, false, 0);
   log().log(DEBUG, job->toString());
   clientReqQueue->put(job);
 
   log().log(DEBUG, "waiting for the NodeHello");
   job->wait(0);
   log().log(DEBUG, "NodeHello arrived");
-//  cout << "Izlaz:\n" << job->getResponse()[0]->toString();
 }
 
 Node::~Node()
 {
   executor.interrupt();
 }
+
+FCPListPeersResult
+Node::listPeers(bool withMetaData = false,
+                bool withVolatile = false){
+  Message::MessagePtr m = Message::factory( std::string("ListPeers") );
+  m->setField("WithMetadata", withMetaData ? "true" : "false");
+  m->setField("WithVolatila", withVolatile ? "true" : "false");
+
+  JobTicket::JobTicketPtr job = JobTicket::factory( "__hello", m, false, false, false, 0 );
+  log().log(DEBUG, job->toString());
+  clientReqQueue->put(job);
+
+  //TODO: finish
+}
+

Modified: trunk/apps/CppFCPLib/Node.h
===================================================================
--- trunk/apps/CppFCPLib/Node.h	2007-06-10 21:46:45 UTC (rev 13512)
+++ trunk/apps/CppFCPLib/Node.h	2007-06-11 09:52:17 UTC (rev 13513)
@@ -3,10 +3,13 @@
 
 #include <string>
 #include <memory>
+
 #include "zthread/Thread.h"
 #include "zthread/ThreadedExecutor.h"
+
 #include "TQueue.h"
 #include "NodeThread.h"
+#include "FCPListPeersResult.h"
 
 namespace FCPLib {
 class Node {
@@ -20,6 +23,8 @@
 public:
   Node(std::string name, std::string host, int port);
   ~Node();
+
+  FCPListPeersResult listPeers(bool, bool);
 };
 }
 

Modified: trunk/apps/CppFCPLib/NodeThread.cpp
===================================================================
--- trunk/apps/CppFCPLib/NodeThread.cpp	2007-06-10 21:46:45 UTC (rev 13512)
+++ trunk/apps/CppFCPLib/NodeThread.cpp	2007-06-11 09:52:17 UTC (rev 13513)
@@ -17,7 +17,7 @@
 }
 
 void NodeThread::run(){
-  Message::MessagePtr m;
+  ServerMessage::ServerMessagePtr m;
   JobTicket::JobTicketPtr job;
   log().log(DETAIL, "FCPNode: manager thread starting");
   try {
@@ -26,7 +26,7 @@
       log().log(NOISY, "_mgrThread: Testing for incoming message");
       if (s.dataAvailable()){
         log().log(DEBUG, "_mgrThread: Retrieving incoming message");
-        m = Message::factory(s);
+        m = ServerMessage::factory(s);
         log().log(DEBUG, "_mgrThread: Got incoming message, dispatching");
         // dispatch the message
         doMessage(m);
@@ -49,7 +49,7 @@
 NodeThread::sendClientReq(JobTicket::JobTicketPtr &job)
 {
   log().log(NOISY, "sendClientReq : top");
-  if (job->commandName() != "WatchGlobal") {
+  if (job->getCommandName() != "WatchGlobal") {
     log().log(NOISY, "sendClientReq : about to add the job to the map");
     (*jobs)[job->getId()] = job;
     log().log(NOISY, "sendClientReq : added the job to the map");
@@ -60,55 +60,22 @@
   job->reqSentLock.release();
 }
 
-//
-//void NodeThread::_hello(){
-//    string message;
-//    message = Message::toString("ClientHello", 2, "Name", this->name.c_str(), "ExpectedVersion", "2.0");
-//    messageQSend->put(message);
-//    logfile->log(DETAIL, message);
-//
-//    message = this->_rxMsg();
-//    Message* nodeHello = new Message(message);
-//    const char * tmp;
-//    if ((tmp = nodeHello->getField("FCPVersion")) != NULL){
-//        this->nodeFCPVersion = string(tmp);
-//    }
-//    if ((tmp = nodeHello->getField("Version")) != NULL){
-//        this->nodeVersion = string(tmp);
-//    }
-//    if ((tmp = nodeHello->getField("Testnet")) != NULL){
-//        this->nodeIsTestnet = (string(tmp) == "true") ? true : false;
-//    }
-//    if ((tmp = nodeHello->getField("CompressionCodes")) != NULL){
-//        this->compressionCodes = atoi(tmp);
-//    }
-//
-//    delete nodeHello;
-//}
-
-
-//
-//string NodeThread::_rxMsg(){
-//  string message = messageQReceive->get();
-//  logfile->log(DETAIL, message);
-//  return message;
-//}
-//
-//void NodeThread::_on_rxMsg(std::string& message){
-//  Message m(message);
-//
-//  logfile->log(DEBUG, m.toString());
-//}
-
 void
-NodeThread::doMessage(Message::MessagePtr &message)
+NodeThread::doMessage(ServerMessage::ServerMessagePtr &message)
 {
   JobTicket::JobTicketPtr job;
-  if (message->getHeader() == "NodeHello"){
-    job = jobs->find("__hello")->second;
-    job->nodeResponse.push_back(message);
-    job->putResult();
+  std::map<std::string, JobTicket::JobTicketPtr>::iterator it;
+
+  it = jobs->find(message->getIdOfJob());
+  if (it == jobs->end()) {
+    log().log(DEBUG, "doMessage : received NodeHello, cannot find __hello in started jobs");
     return;
   }
+
+  job = it->second;
+  job->nodeResponse.push_back(message);
+  if (message->isLastMessage(job->getCommandName())) {
+    job->putResult();
+  }
 }
 

Modified: trunk/apps/CppFCPLib/NodeThread.h
===================================================================
--- trunk/apps/CppFCPLib/NodeThread.h	2007-06-10 21:46:45 UTC (rev 13512)
+++ trunk/apps/CppFCPLib/NodeThread.h	2007-06-11 09:52:17 UTC (rev 13513)
@@ -8,29 +8,25 @@
 #include <map>
 #include <string>
 #include "JobTicket.h"
+#include "ServerMessage.h"
 
 namespace FCPLib {
 
 class Node;
 
-typedef TQueue<JobTicket::JobTicketPtr> JobTicketQueue;
+typedef TQueue< JobTicket::JobTicketPtr > JobTicketQueue;
 
 class NodeThread : public ZThread::Runnable {
-//  ZThread::CountedPtr<Logger> logfile;
   ZThread::CountedPtr< JobTicketQueue > clientReqQueue;
   FCPLib::Server s;
-  ZThread::CountedPtr< std::map<std::string, JobTicket::JobTicketPtr> > jobs;
 
-//  void _hello();
-//  static std::string _getUniqueId();
-//  std::string _rxMsg();
-//  void _on_rxMsg(std::string &message);
+  ZThread::CountedPtr< std::map<std::string, JobTicket::JobTicketPtr > > jobs;
 
   friend class Node;
   NodeThread(std::string &host, int port, ZThread::CountedPtr< JobTicketQueue > &clientReqQueue_) throw();
 
   void sendClientReq(JobTicket::JobTicketPtr &job);
-  void doMessage(Message::MessagePtr &message);
+  void doMessage(ServerMessage::ServerMessagePtr &message);
 public:
   void run();
 };

Added: trunk/apps/CppFCPLib/PeerMessage.h
===================================================================
--- trunk/apps/CppFCPLib/PeerMessage.h	                        (rev 0)
+++ trunk/apps/CppFCPLib/PeerMessage.h	2007-06-11 09:52:17 UTC (rev 13513)
@@ -0,0 +1,34 @@
+#ifndef PEERMESSAGE_H__
+#define PEERMESSAGE_H__
+
+#include <string>
+#include <stdexcept>
+
+namespace FCPLib {
+
+class ServerMessage;
+
+class PeerMessage : public ServerMessage {
+  PeerMessage() {}
+public:
+  std::string getIdOfJob() const
+  {
+    return "__global";
+  }
+
+  bool isLastMessage(const std::string &cmd) const
+  {
+    if (cmd == "ListPeers")
+      return false;
+    else if (cmd == "ModifyPeer")
+      return true;
+
+    throw new std::runtime_error("Unknown command");
+  }
+
+  friend class ServerMessage;
+};
+
+}
+
+#endif // PEERMESSAGE_H__

Added: trunk/apps/CppFCPLib/ServerMessage.cpp
===================================================================
--- trunk/apps/CppFCPLib/ServerMessage.cpp	                        (rev 0)
+++ trunk/apps/CppFCPLib/ServerMessage.cpp	2007-06-11 09:52:17 UTC (rev 13513)
@@ -0,0 +1,43 @@
+
+#include "ServerMessage.h"
+#include "PeerMessage.h"
+
+using namespace FCPLib;
+
+
+ServerMessage::ServerMessagePtr
+ServerMessage::factory(Server &s){
+  ServerMessage::ServerMessagePtr m;
+  static char line[1000];
+
+  s.readln(line, 1000);
+  line[strlen(line)-1] = 0;
+  std::string header = std::string(line);
+
+  if (header == "Peer") {
+    m = ServerMessagePtr( new PeerMessage() );
+  }
+  m->message = Message::factory(header);
+
+  m->read(s);
+
+  return m;
+}
+
+void ServerMessage::read(Server &s)
+{
+    static char line[1000];
+    for (;;) {
+    s.readln(line, 1000);
+    line[strlen(line)-1] = 0;
+
+    if (!strcmp(line, "End") || !strcmp(line, "EndMessage"))
+      break;
+
+    char *val = strchr(line, '=');
+    *val++ = 0;
+    message->setField(std::string(line), std::string(val));
+  }
+}
+
+

Added: trunk/apps/CppFCPLib/ServerMessage.h
===================================================================
--- trunk/apps/CppFCPLib/ServerMessage.h	                        (rev 0)
+++ trunk/apps/CppFCPLib/ServerMessage.h	2007-06-11 09:52:17 UTC (rev 13513)
@@ -0,0 +1,24 @@
+#ifndef SERVERMESSAGE_H__
+#define SERVERMESSAGE_H__
+
+#include "Message.h"
+#include "Server.h"
+
+namespace FCPLib {
+
+class ServerMessage {
+  Message::MessagePtr message;
+
+  void read(Server &s);
+public:
+  typedef boost::shared_ptr<ServerMessage> ServerMessagePtr;
+  static ServerMessagePtr factory(Server &s);
+
+  virtual std::string getIdOfJob() const = 0;
+  virtual bool isLastMessage(const std::string &cmd) const = 0;
+  virtual ~ServerMessage() {}
+};
+
+}
+
+#endif // SERVERMESSAGE_H__




More information about the Cppfcplib mailing list