moss-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Moss-devel] CVS: moss/rmc/src/Demos/Chat/Client Chat_c.cxx,NONE,1.1 Cha


From: Alexander Feder <address@hidden>
Subject: [Moss-devel] CVS: moss/rmc/src/Demos/Chat/Client Chat_c.cxx,NONE,1.1 Chat_c.h,NONE,1.1 Makefile.am,NONE,1.1 main.cxx,NONE,1.1
Date: Sun, 23 Jun 2002 09:27:52 -0400

Update of /cvsroot/moss/moss/rmc/src/Demos/Chat/Client
In directory subversions:/tmp/cvs-serv2212/src/Demos/Chat/Client

Added Files:
        Chat_c.cxx Chat_c.h Makefile.am main.cxx 
Log Message:
added rmc


--- NEW FILE ---
/***************************************************************************
                               Chat_c.cxx
                           -------------------
    begin                : Sun Mai 03 2001
    copyright            : (C) 2001 by Manfred Morgner
    email                : address@hidden

 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *                                                                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place Suite 330,                                            *
 *   Boston, MA  02111-1307, USA.                                          *
 *                                                                         *
 ***************************************************************************
 *
 *  conceptional code - assigned to KM until it's running
 *
 *  RMC.2 sample application.
 *
 *  Client Side: A simple chat client using 2 remote methods
 *  "Send(.)" and "Receive(.)"
 */

#include "generic.h"
#include "Chat_c.h"

// RMC generated ->
using namespace rmc;

// RTTI
TRmcClass CChat::s_nRtti = RTTI_CCHAT; // to manage !

/* RMC - interface:
long   CChat::Send(const string &s);
long   CChat::Receive(string &s);
void   Chat::GetHistory(long nIndex, string &s);
string Chat::GetHistory();
void   Chat::SetParameter(const string &sNick, long nOptions);
*/

// <- RMC generated

CChat::CChat(const string &sComputer,
             const string &sLogin,
             const string &sPassword)
  {
  TRACE("Constructor CChat\n");
  rmc_c_m_oRmcClient.RemoteSystemConfig(sComputer, sLogin, sPassword);
  TRACE("\tconnecting to the server\n");
  rmc_c_m_oRmcClient.ObjectConnect(RTTI_CCHAT);
  } // CChat::CChat(const string &sComputer, ...

CChat::~CChat()
  {
  } // CChat::~CChat()
  

--- NEW FILE ---
/***************************************************************************
                                Chat_c.h
                           -------------------
    begin                : Sun Mai 03 2001
    copyright            : (C) 2001 by Manfred Morgner
    email                : address@hidden

 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *                                                                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place Suite 330,                                            *
 *   Boston, MA  02111-1307, USA.                                          *
 *                                                                         *
 ***************************************************************************
 *
 *  conceptional code - assigned to KM until it's running
 */

#ifndef __CHAT_CLIENT_CLASS_H
#define __CHAT_CLIENT_CLASS_H

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#if __GNU__ >= 2
#  pragma interface
#endif // __GNU__ >= 2


// RMC Helper
#include "RmcClient.h"

/***************************************************************************

 THIS IS A SAMPLE CLASS! IN A REAL PROJECT THE CLASS DEFINTION
 AND IMPLEMENTATION HAS TO GO INTO TWO OTHER FILES CURRENTLY
 THIS DEMONSTRATION AND DEVELOPMENT APPLICATION HAS TO HAVE A
 SIMPLE PROJECT STRUCTURE. THATS WHY I INSERTED THE COMPLETE DUMMY
 CLASS FOR TESTING PRPOSE ON THIS POINT.

 For technical information:

 The classes on both sides of the system (Client/Server) have to
 be _compatible_. There is no reason to share the same code. Only
 the methods _RMC_put(..) and _RMC_get(..) have to have a
 compatible behavior!

 So, if you never wish to receive a CAgent on the client side,
 you do not need to implement the _RMC_get(..) methode. The same
 is for the server. If the server never wish to send an object to
 an other destination, he is not in need to have a _RMC_put(..)
 methode.

 ***************************************************************************/

class CAgent // for development reason declared and implemented here
  {
        string m_sCode;
  
  public:
        // RMC transport helper methods
        long _RMC_size()
          {
          return m_sCode.length() +1;
          }

  bool _RMC_put(rmc::TRmcData*& rpData)
          {
          strcpy(rpData, m_sCode.c_str());
          return true;
          }

//-     bool _RMC_get(TRmcData* rpData)
//-       {
//-       m_sCode = (char*)rpData;
//-       return true;
//-       }

};
// the indides to the RMT (remote methode table) on the server side
// rmcgen ensures to correct assignments by generating matching classes
#define MID_Send_0         0L // long Send(const string &s)
#define MID_Receive_0      1L // long Receive(string &s)
#define MID_GetHistory_0   2L // void GetHistory(long nIndex, string &s)
#define MID_GetHistory_1   3L // string GetHistory()
#define MID_SetParameter_0 4L // void SetParameter(const string &sNick, long 
nOptions)
#define MID_Send_1         5L // void Send(CAgent &oAgent)
#define MID_StartAgents_0  6L // void StartAgents()

/*
// remote methode table for class CChat
enum RMT_CCHAT
  {
  MID_Chat_Send_0        = 0L; // long Send(const string &s)
  MID_Chat_Receive_0       1L; // long Receive(string &s)
  MID_Chat_GetHistory_0    2L; // void GetHistory(long nIndex, string &s)
  MID_Chat_GetHistory_1    3L; // string GetHistory()
  MID_Chat_SetParameter_0  4L  // void SetParameter(const string &sNick, long 
nOptions)
  };
*/



// the runtime type information code for this class neccessary by the server
#define RTTI_CCHAT 0x77973323

class CChat
  {
  public:  
    CChat(const string &sComputer,
      const string &sLogin    = _T(""),
      const string &sPassword = _T(""));
    
    virtual ~CChat();
    
    // RTTI (runtime type information)
  private:
    // implemented in the CXX file
    static rmc::TRmcClass s_nRtti;
    
  public:
    // the methode to get the RTTI from an instance
    virtual rmc::TRmcClass RttiGet() { return s_nRtti; }
    // the methode to get the RTTI from the class
    static  rmc::TRmcClass RTTI()    { return s_nRtti; }
    
    // RMC distribution
  private:
    // special naming convention for RMC/RPC related members to prevent
    // naming collision with unknown usercode
    
    // this is the very private RMC-connection controller
    // it holds all data neccessary to manage instance assignment
    // to the server side, security data and mechanis for the
    // transport and handles the remote method calls
    rmc::CRmcClient rmc_c_m_oRmcClient;
    
    // the transport related result of the last RMC call
    rmc::TRmcResult rpc_c_m_nLastCallResult;
    
    // RMC calling code
  public:

    // s: IN, transport as "char*"
    long Send(const string &s)
      {
      rmc::TRmcSize  rmc_c_v_nSize  = s.length() +1;
      rmc::TRmcData *rmc_c_v_pcData = new char[rmc_c_v_nSize];
      strncpy((char*)&rmc_c_v_pcData[0], s.c_str(), s.length() +1);

      rmc::TRmcResult rmc_c_r_nResult = rmc_c_m_oRmcClient.Call(MID_Send_0, 
rmc_c_v_nSize, rmc_c_v_pcData);
      rpc_c_m_nLastCallResult = rmc_c_r_nResult;

      // the return value, type as given int the methode declaration
      long rmc_c_r_nReturnValue; // initialisation ??

      // mapping the output to the OUT-arguments
      // if the call returns anything
      if ( (rmc_c_r_nResult == rmc::RMC_SUCCESS) && (rmc_c_v_nSize > 0) ) // > 
0 ??
        {
        // we have to trust m_rmc_o_RmcClient, this class has to
        // check the return values - as far as possible

        memcpy(&rmc_c_r_nReturnValue, rmc_c_v_pcData, 
sizeof(rmc_c_r_nReturnValue));
        } // if (nSize > 0)
      
      // delete the buffer if allocated
#ifndef WIN32
      delete rmc_c_v_pcData;
#endif      
      return rmc_c_r_nReturnValue;
      } // long Send(const string &s)
    
    // s: OUT, transport as "char*"
    long Receive(string &s)
      {
      rmc::TRmcSize  rmc_c_v_nSize  = 0; // we will not send anything
      rmc::TRmcData *rmc_c_v_pcData = 0; // RMA (Remote Memory Allocation 
expected)
      
      rmc::TRmcResult rmc_c_r_nResult = rmc_c_m_oRmcClient.Call(MID_Receive_0, 
rmc_c_v_nSize, rmc_c_v_pcData);
      rpc_c_m_nLastCallResult = rmc_c_r_nResult;
      
      // the return value, type as givrn int the methode declaration
      long rmc_c_r_nReturnValue; // initialisation ??
      
      // map the output to the OUT-arguments
      // if the call returns anything
      if ( (rmc_c_r_nResult == rmc::RMC_SUCCESS) && (rmc_c_v_nSize > 0) ) // > 
0 ??
        {
        // we have to trust m_rmc_o_RmcClient, this class has to
        // check the return values - as far as possible
        
        // the output read position only neccesary if more than one
        // OUT parameter comes in
        rmc::TRmcMemPos rmc_c_v_nOutPos = 0;
        memcpy(&rmc_c_r_nReturnValue, &(rmc_c_v_pcData[rmc_c_v_nOutPos]), 
sizeof(rmc_c_r_nReturnValue));
        rmc_c_v_nOutPos += sizeof(rmc_c_r_nReturnValue);
        s = &(rmc_c_v_pcData[rmc_c_v_nOutPos]);
        // not neccessary: nOutPos += s.length() +1;
        } // if (nSize > 0)
      
      // delete the buffer if allocated
#ifndef WIN32
      delete rmc_c_v_pcData;
#endif      
      // return the calling result ??? 
      return rmc_c_r_nReturnValue;
      } // long Receive(string &s)
    
    // nIndex: IN,  index in the history relative
    //              to the starting point of the stub instance
    // s.....: OUT, transport as "char*"
    //              the OUT(-only) attribut is given by declaration
    void GetHistory(long nIndex, /* out */ string &s)
      {
      rmc::TRmcSize  rmc_c_v_nSize  = sizeof(nIndex);          // only nIndex 
goes to the server
      rmc::TRmcData *rmc_c_v_pcData = new char[rmc_c_v_nSize]; // RMA expected !
      
      memcpy(rmc_c_v_pcData, &nIndex, sizeof(nIndex));
      
      rmc::TRmcResult rmc_c_r_nResult = 
rmc_c_m_oRmcClient.Call(MID_GetHistory_0, rmc_c_v_nSize, rmc_c_v_pcData);
      rpc_c_m_nLastCallResult = rmc_c_r_nResult;
      
      // map the output to the OUT-arguments
      // if the call returns anything
      if ( (rmc_c_r_nResult == rmc::RMC_SUCCESS) && (rmc_c_v_nSize > 0) ) // > 
0 ??
        {
        // we have to trust m_rmc_o_RmcClient, this class has to
        // check the return values - as far as possible
        
        s = rmc_c_v_pcData; // means: s = &(pcData[nOutPos]);
        } // if (nSize > 0)
      
      // delete the buffer if allocated
#ifndef WIN32
      delete rmc_c_v_pcData;
#endif      
      } // long GetHistory(long nIndex, string &s)
    
    // return: the next line from the history (backward)
    // the answer (read index) is managed by the stub (server sided)
    string GetHistory()
      {
      rmc::TRmcSize  rmc_c_v_nSize  = 0; // we will not send anything
      rmc::TRmcData *rmc_c_v_pcData = 0; // RMA (Remote Memory Allocation 
expected)
      
      rmc::TRmcResult rmc_c_r_nResult = 
rmc_c_m_oRmcClient.Call(MID_GetHistory_1, rmc_c_v_nSize, rmc_c_v_pcData);
      rpc_c_m_nLastCallResult = rmc_c_r_nResult;
      
      // the return value, type as givrn int the methode declaration
      string rmc_c_r_sReturnValue; // a class -> do not initializs
      
      // map the output to the OUT-arguments
      // if the call returns anything
      if ( (rmc_c_r_nResult == rmc::RMC_SUCCESS) && (rmc_c_v_nSize > 0) ) // > 
0 ??
        {
        // we have to trust m_rmc_o_RmcClient, this class has to
        // check the return values - as far as possible
        
        rmc_c_r_sReturnValue = rmc_c_v_pcData; // means: sReturnValue = 
&(pcData[nOutPos]);
        } // if (nSize > 0)
      
      // delete the buffer if allocated
#ifndef WIN32
      delete rmc_c_v_pcData;
#endif      
      // return the calling result ??? 
      return rmc_c_r_sReturnValue;
      } // string GetHistory()
    
    // IN: sNick
    // IN: nOptions
    void SetParameter(const string &sNick, long nOptions)
      {
      // the input write position, only used if more than one
      // IN arguments given for transport
      rmc::TRmcMemPos rmc_c_v_nInPos = 0;
      // set variables for each parameter than can't be used with 'sizeof()'
      const rmc::TRmcSize rmc_c_v_nSize_sNick = sNick.length() +1;
      // the IN buffer size
      rmc::TRmcSize rmc_c_v_nSize  = rmc_c_v_nSize_sNick   // sNick
                                     + sizeof(nOptions);   // nOption
      // the IN buffer
      rmc::TRmcData *rmc_c_v_pcData = new char[rmc_c_v_nSize];
      // copy sNick as 'char*'
      strncpy((char*)&rmc_c_v_pcData[0], sNick.c_str(), sNick.length() +1);
      // add the size from the last copy operation to the write position
      rmc_c_v_nInPos += rmc_c_v_nSize_sNick;
      // copy nOption
      memcpy(&(rmc_c_v_pcData[rmc_c_v_nInPos]), &nOptions, sizeof(nOptions));
      // not neccessary: nInPos += sizeof(nOptions);
      
      // call the remote methode
      rmc::TRmcResult rmc_c_r_nResult = 
rmc_c_m_oRmcClient.Call(MID_SetParameter_0, rmc_c_v_nSize, rmc_c_v_pcData);
      rpc_c_m_nLastCallResult = rmc_c_r_nResult;
      
      // delete the buffer if allocated
#ifndef WIN32
      delete rmc_c_v_pcData;
#endif      
      } // void SetParameter(const string &sNick, long nOptions)
    
    // IN: roAgent
    void Send(/*[in,object]*/ CAgent &roAgent)
      {
      // the IN buffer size
      rmc::TRmcSize  rmc_c_v_nSize  = roAgent._RMC_size();
      // the IN buffer
      rmc::TRmcData *rmc_c_v_pcData = new char[rmc_c_v_nSize];
      // let the object copy his data to the buffer
      roAgent._RMC_put(rmc_c_v_pcData);
      
      // call the remote methode
      rmc::TRmcResult rmc_c_r_nResult = rmc_c_m_oRmcClient.Call(MID_Send_1, 
rmc_c_v_nSize, rmc_c_v_pcData);
      rpc_c_m_nLastCallResult = rmc_c_r_nResult;
      
      } // void Send(/*[out,object]*/ CAgent &oAgent)
    
    void StartAgents()
      {
      rmc::TRmcSize  rmc_c_v_nSize  = 0;
      rmc::TRmcData *rmc_c_v_pcData = 0;
      // call the remote methode
      rmc::TRmcResult rmc_c_r_nResult = 
rmc_c_m_oRmcClient.Call(MID_StartAgents_0, rmc_c_v_nSize, rmc_c_v_pcData);
      rpc_c_m_nLastCallResult = rmc_c_r_nResult;
      } // void StartAgents()
    
}; // class CChat

#undef MID_Send_0
#undef MID_Receive_0
#undef MID_GetHistory_0
#undef MID_GetHistory_1
#undef MID_SetParameter_0
#undef MID_Send_1
#undef MID_StartAgents_0

#endif // __CHAT_CLIENT_CLASS_H

--- NEW FILE ---
bin_PROGRAMS = chatclient


CFLAGS=-D_REENTRANT
CXXFLAGS = -Wall -g -O2
INCLUDES=-I../../../../include

chatclient_SOURCES = Chat_c.cxx main.cxx
#chatclient_LDADD = ../../../../src/Client/libRmcClient.a 
../../../../src/family/libFamily.la -ldl -lstdc++ 
chatclient_LDADD = ../../../../src/Client/libRmcClient.a -ldl -lstdc++ 

--- NEW FILE ---
/***************************************************************************
                                main.cxx
                           -------------------
    begin                : Sun Mai 03 2001
    copyright            : (C) 2001 by Manfred Morgner
    email                : address@hidden

 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *                                                                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place Suite 330,                                            *
 *   Boston, MA  02111-1307, USA.                                          *
 *                                                                         *
 ***************************************************************************/

// #define _DEBUG

#include "generic.h"
#include "Chat_c.h"


int main( int argc, char** argv )
  {
  string sHost = "localhost";
  string sPort = "6666";
  string s     = "Pelsonat perato naaki";
  
  switch ( argc )
          {
          case 4:
                  s = argv[3];
          case 3:
                  sPort = argv[2];
          case 2: 
                  sHost = argv[1];
          default:
                  break;
          }
  string sTarget = sHost + ":" + sPort;
#ifdef _DEBUG
  cout << "Connecting to " << sTarget << endl;
#endif // _DEBUG
  CChat oChat(_T(sTarget));



  oChat.Send(s);
  
  s = ""; oChat.Receive(s);
  TRACE(">>>>>>>> Recv: \"") TRACE(s) TRACE("\"\n")
  SLEEP(5000);
  s = ""; oChat.Receive(s);
  TRACE(">>>>>>>> Recv: \"") TRACE(s) TRACE("\"\n")

  string sHistory = oChat.GetHistory();
  
  TRACE(">>>>>>>> Recv: \"") TRACE(sHistory) TRACE("\"\n")
  
  oChat.GetHistory(3, sHistory);

  TRACE(">>>>>>>> Recv: \"") TRACE(sHistory) TRACE("\"\n")
  
  oChat.SetParameter("'KM21'", 2);
  
  CAgent oAgent;
  oChat.Send(oAgent);
  oChat.StartAgents();

/*
  oChat.Send("Pelsonat perato naaki");
  oChat.Send("Tulo ferilo pe antana");
  oChat.Send("Kento kalino lotation");

  TRACE("Receive\n");

  s = ""; oChat.Receive(s);
  TRACE(">>>>>>>> Recv: \"") TRACE(s) TRACE("\"\n")
  s = ""; oChat.Receive(s);
  TRACE(">>>>>>>> Recv: \"") TRACE(s) TRACE("\"\n")
  s = ""; oChat.Receive(s);
  TRACE(">>>>>>>> Recv: \"") TRACE(s) TRACE("\"\n")
*/
  return 0;
  } // main()




reply via email to

[Prev in Thread] Current Thread [Next in Thread]