Added Multiple Channels and Event support to RPC system.

* added chan_id parameter to many RPC calls, this allows RPC to support multiple SSH clients.
     - the combination of (chan_id, req_id) rather than req_id, should be unique now  
     		-> TODO inside rpcserver queued requests.
 * Modified SSH server to match the new API. Multiple client support has not been added here yet.
 * Modified Menu System to match these changes too.
 * Added an Registration Framework to RpcQueueService, to enable easy event support.
 
This code has not been throughly tested yet.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5500 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-09-01 19:35:23 +00:00
parent 46c945de96
commit 9c2f7f39e7
17 changed files with 435 additions and 117 deletions

View file

@ -37,7 +37,7 @@
*/
// RsTermServer Interface.
void MenuInterface::reset()
void MenuInterface::reset(uint32_t /* chan_id */)
{
mBase->reset();
mCurrentMenu = mBase;
@ -59,7 +59,9 @@ int MenuInterface::tick()
uint8_t keypress;
std::string output;
int read = mComms->recv(&keypress, 1);
uint32_t chan_id = 1; // dummy - for menu system.
int read = mComms->recv(chan_id, &keypress, 1);
#ifdef MENU_DEBUG
std::cerr << "MenuInterface::tick() read " << read << " bytes";
std::cerr << std::endl;
@ -78,7 +80,7 @@ int MenuInterface::tick()
else
{
/* error, NON BLOCKING is handled by recv returning 0 */
mComms->error("Bad Input");
mComms->error(chan_id, "Bad Input");
return -1;
}
@ -121,7 +123,7 @@ int MenuInterface::tick()
if (output.size() > 0)
{
mComms->send(output);
mComms->send(chan_id, output);
}
return (haveInput);

View file

@ -232,7 +232,7 @@ public:
uint32_t drawHeader(uint32_t drawFlags, std::string &buffer);
// RsSystem Interface.
virtual void reset();
virtual void reset(uint32_t chan_id);
virtual int tick();

View file

@ -66,7 +66,16 @@ int StdioComms::isOkay()
}
int StdioComms::error(std::string msg)
int StdioComms::active_channels(std::list<uint32_t> &chan_ids)
{
if (isOkay())
{
chan_ids.push_back(1); // only one possible here (stdin/stdout)
}
return 1;
}
int StdioComms::error(uint32_t chan_id, std::string msg)
{
std::cerr << "StdioComms::error(" << msg << ")";
std::cerr << std::endl;
@ -75,14 +84,14 @@ int StdioComms::error(std::string msg)
int StdioComms::recv_ready()
int StdioComms::recv_ready(uint32_t chan_id)
{
/* should be proper poll / select! - but we don't use this at the moment */
return 1;
}
int StdioComms::recv(uint8_t *buffer, int bytes)
int StdioComms::recv(uint32_t chan_id, uint8_t *buffer, int bytes)
{
int size = read(mIn, buffer, bytes);
std::cerr << "StdioComms::recv() returned: " << size;
@ -102,7 +111,7 @@ int StdioComms::recv(uint8_t *buffer, int bytes)
}
int StdioComms::recv(std::string &buffer, int bytes)
int StdioComms::recv(uint32_t chan_id, std::string &buffer, int bytes)
{
uint8_t tmpbuffer[bytes];
int size = read(mIn, tmpbuffer, bytes);
@ -114,7 +123,7 @@ int StdioComms::recv(std::string &buffer, int bytes)
}
// these make it easier...
int StdioComms::recv_blocking(uint8_t *buffer, int bytes)
int StdioComms::recv_blocking(uint32_t chan_id, uint8_t *buffer, int bytes)
{
int totalread = 0;
while(totalread < bytes)
@ -137,10 +146,10 @@ int StdioComms::recv_blocking(uint8_t *buffer, int bytes)
}
int StdioComms::recv_blocking(std::string &buffer, int bytes)
int StdioComms::recv_blocking(uint32_t chan_id, std::string &buffer, int bytes)
{
uint8_t tmpbuffer[bytes];
int size = recv_blocking(tmpbuffer, bytes);
int size = recv_blocking(chan_id, tmpbuffer, bytes);
if (size < 0)
return size; // error.
@ -152,14 +161,14 @@ int StdioComms::recv_blocking(std::string &buffer, int bytes)
}
int StdioComms::send(uint8_t *buffer, int bytes)
int StdioComms::send(uint32_t chan_id, uint8_t *buffer, int bytes)
{
write(mOut, buffer, bytes);
return bytes;
}
int StdioComms::send(const std::string &output)
int StdioComms::send(uint32_t chan_id, const std::string &output)
{
if (output.size() > 0)
{

View file

@ -36,18 +36,20 @@ public:
StdioComms(int infd, int outfd);
virtual int isOkay();
virtual int error(std::string msg);
virtual int error(uint32_t chan_id, std::string msg);
virtual int recv_ready();
virtual int recv(uint8_t *buffer, int bytes);
virtual int recv(std::string &buffer, int bytes);
virtual int active_channels(std::list<uint32_t> &chan_ids);
virtual int recv_ready(uint32_t chan_id);
virtual int recv(uint32_t chan_id, uint8_t *buffer, int bytes);
virtual int recv(uint32_t chan_id, std::string &buffer, int bytes);
// these make it easier...
virtual int recv_blocking(uint8_t *buffer, int bytes);
virtual int recv_blocking(std::string &buffer, int bytes);
virtual int recv_blocking(uint32_t chan_id, uint8_t *buffer, int bytes);
virtual int recv_blocking(uint32_t chan_id, std::string &buffer, int bytes);
virtual int send(uint8_t *buffer, int bytes);
virtual int send(const std::string &buffer);
virtual int send(uint32_t chan_id, uint8_t *buffer, int bytes);
virtual int send(uint32_t chan_id, const std::string &buffer);
private:
int mIn, mOut;