Exemplo n.º 1
0
    void run()
    {
        GLock<1> lock;
        std::string msg;
        lock.lock();
        BQueue<std::string>* pBQ = _pFileHandler->getQueue();
        ICommunicator* pComm = _pFileHandler->getCommunicator();
        EndPoint remoteEp = _pFileHandler->getEndPoint();
        lock.unlock();
        ///////////////////////////////////////////////////////
        // insert your server code here
        while(true)
        {
            sout << locker << "\n  receiver processing file: " << (msg = pBQ->deQ()).c_str() << unlocker;
            //lock.lock();
            //EndPoint remoteEp = _pFileHandler->getEndPoint();
            //if(pComm->connect(remoteEp.getIP(), remoteEp.getPort()))
            //{
            //  pComm->postMessage(std::string("got file"));
            //  pComm->disconnect();
            //}
            //else
            //  sout << "\n  failed to connect";
            //lock.unlock();

            if(msg == "quit")
                break;
        }
        // end of your code
        ///////////////////////////////////////////////////////
    }
void MockChannel::start()
{
  std::cout << "\n  MockChannel starting up";
  thread_ = std::thread(
    [this] {
    while (!stop_)
    {
      std::cout << "\n  channel deQing message";
	  MessageS msg = sendQ_.deQ();  // will block here so send quit message when stopping
	  std::cout << "\n  channel enQing message";
      recvQ_.enQ(msg);
	  std::cout << msg;
	}
    std::cout << "\n  Server stopping\n\n";
  });
}
Exemplo n.º 3
0
void ClientFile_Proc::run()
{
	GLock<1> lock;
	std::string msg;
	lock.lock();
	BQueue<std::string>* pBQ = _pFileHandler->getQueue();
	//ICommunicator* pComm = _pFileHandler->getCommunicator();
	//EndPoint remoteEp = _pFileHandler->getEndPoint();
	lock.unlock();

	while(true)
	{
		sout << locker << "\n  Client received file: " 
			<< (msg = pBQ->deQ()).c_str() << unlocker;
	}
}
void Sendr::postMessage(const MessageS& msg)
{
  sendQ_.enQ(msg);
  string file = FileSystem::Path::fileSpec("../TESTFOLDERCLIENT1", "test.txt");
  string filepath = FileSystem::Path::getFullFileSpec(file);
  Client1 c1("localhost","1001","localhost","2001",filepath);
  c1.enQueue("TEST_FILE_REQUEST",filepath);
}
Exemplo n.º 5
0
	void run()
	{
		GLock<1> lock;
		std::string msg;
		lock.lock();
		BQueue<std::string>* pBQ = _pFileHandler->getQueue();
		ICommunicator* pComm = _pFileHandler->getCommunicator();
		EndPoint remoteEp = _pFileHandler->getEndPoint();
		lock.unlock();
		///////////////////////////////////////////////////////
		// enter your server code here
		while(true)
		{
			sout << locker << "\n  sender received file: " 
				<< (msg = pBQ->deQ()).c_str() << unlocker;
			if(msg == "quit")
				break;
		}
		// end of your code
		///////////////////////////////////////////////////////
	}
Exemplo n.º 6
0
void ClientMessage_Proc::run()
{
	GLock<1> lock;
	std::string msg;
	lock.lock();
	BQueue<std::string>* pBQ = _pMsgHandler->getQueue();
	ICommunicator* pComm = _pMsgHandler->getCommunicator();
	EndPoint remoteEp = _pMsgHandler->getEndPoint();
	lock.unlock();
	///////////////////////////////////////////////////////
	// enter your server code here
	while(true)
	{
		msg = pBQ->deQ();
		sout << locker << "\n\n  Client received message: \n" 
			<< msg << unlocker;

		FormMessageHanlder->ReceiveMessage(msg);
	}
	// end of your code
	///////////////////////////////////////////////////////
}
Exemplo n.º 7
0
void main() {

  cout << "\n  Demonstrating basic Queue operations with the BlockingQueue<T> class "
       << "\n ======================================================================\n";

  BQueue<int> intQ;
  intQ.enQ(1);
  intQ.enQ(2);
  intQ.enQ(3);

  BQueue<int> intQ2 = intQ;
  cout << "\n  copy construction: intQ2.size() = " << intQ2.size();
  intQ2.clear();
  cout << "\n  after intQ2.clear(), intQ2.size() = " << intQ2.size();

  BQueue<int> intQ3;
  intQ3 = intQ;
  cout << "\n  after assignment: intQ3.size() = " << intQ3.size();

  cout << "\n  intQ3 contents: " 
       << intQ3.deQ() << "," << intQ3.deQ() << "," << intQ3.deQ() << "\n\n";

  cout << "\n  Demonstrating BlockingQueue<T> message handling "
       << "\n =================================================\n";

  BQueue<std::string> sQ;
  threadproc tp(sQ);
  thread th(tp);
  th.start();
  std::string msg;
  ostringstream out;

  for(int i=0; i<20; ++i)
  {
    out.str("");
    out << i;
    msg = std::string("msg #") + out.str() + std::string(" - a message");
    sout << locker << "\n  sending msg \"" << msg << "\"" << unlocker;
    sQ.enQ(msg);
  }
  msg = std::string("quit");
  sout << locker << "\n  sending msg \"" << msg << "\"" << unlocker;
  sQ.enQ(msg);
  th.wait();
}
void MockChannel::postMessage(const MessageS& cmd, const MessageS& parameter)
{
	c1.enQueue(cmd, parameter);
	sendQ_.enQ(cmd);
	sendQ_.enQ(parameter);
}
MessageS Recvr::getMessage()
{
  return recvQ_.deQ();
}
MessageS MockChannel::getMessage()
{
	recvQ_.deQ();
	return c1.deQueue();
}