Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

commcenter.h

Go to the documentation of this file.
00001 /*
00002   svas_server -- virtual World Server of Svas
00003   Copyright (c) 2001, 2002 David Moreno Montero
00004  
00005  
00006   This program is free software; you can redistribute it and/or modify
00007   it under the terms of the GNU General Public License as published by
00008   the Free Software Foundation; either version 2 of the License, or
00009   (at your option) any later version.
00010  
00011   This program is distributed in the hope that it will be useful, but
00012   WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   General Public License for more details.
00015  
00016   You should have received a copy of the GNU General Public License
00017   along with this program; if not, write to the Free Software
00018   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00019   02111-1307, USA.  
00020 
00021 */
00022 
00023 #ifndef __COMMCENTER__
00024 #define __COMMCENTER__
00025 
00026 #include <thread.h>
00027 #include <iostream>
00028 #include <strchar.h>
00029 #include <exception.h>
00030 #include <socket.h>
00031 #include <vector>
00032 #include <map>
00033 #include <string>
00034 
00035 #include "baseClient.h"
00036 
00037 class World;
00038 class Client;
00039 
00040 /**
00041  * The communication center open several ports to accept incomming
00042  * conections, and when a new conection arrives, it redirects it to
00043  * the client creator (newClient, newGraphicClient...), which creates
00044  * a thread with the client, and go back to the
00045  * check-for-new-conections loop.
00046  */
00047 class CommCenter{
00048  protected:
00049   /** @name Ports 
00050    *
00051    * Ports that wait for incomming connections, that later are
00052    * redirected to channels
00053    * @{
00054    */
00055   ost::TCPSocket *clientPort;
00056   ost::TCPSocket *graphicClientPort;
00057   ost::TCPSocket *controlClientPort;
00058   ost::TCPSocket *serverPort;
00059   /** @} */
00060 
00061   vector<baseClient *> clients;
00062 
00063   /** @name New Conections
00064    * Methods to create new conections, or wait if there is not pending
00065    * conection 
00066    * @{
00067    */
00068   void newClient();
00069   void newGraphicClient();
00070   void newControlClient();
00071   void newServer();
00072   /** @} */
00073 
00074   /** @name Parts of the Main Thread Loop
00075    * The main loop makes several tasks. Each of this methos is one of
00076    * these tasks 
00077    * @{
00078    */
00079   void checkForConections();
00080   void checkForDeadClients();
00081   void removeDeadClients();
00082   void waitForClients();
00083   void makeMovements();
00084   /** @} */
00085 
00086 
00087   /// The world that this commcenter controls 
00088   World *world;
00089   /// A dictionary of name of AgentClients and lists of AgentClients
00090   map<string, vector<Client *>, less<string> > clientMap;
00091 
00092  public:
00093   CommCenter();
00094   ~CommCenter();
00095 
00096   void loop();
00097   void getMessages();
00098 
00099   Client *getClientForMigration(string name);
00100 };
00101 
00102 #endif

Generated on Mon Jun 17 19:53:44 2002 for Svas Server by doxygen1.2.16