Partie Class Reference

Classe permettant de gérer les informations relatives aux parties
Cette classe est un singleton, elle peut donc être utilisée par plusieurs thread en même temps. More...

#include <Partie.h>

Inheritance diagram for Partie:

Inheritance graph
[legend]
Collaboration diagram for Partie:

Collaboration graph
[legend]
List of all members.

Public Member Functions

int Rechercher (unsigned int id)
 Rechercher la position d'une partie dans le tableau.
int AjouterPartie (unsigned int id)
 Ajouter une partie au tableau (Le reste des infos est destiné a être renseigné plus tard).
int AjouterPartie (const PartieInfo &p)
int SupprimerPartie (unsigned int id)
 Supprimer une partir.
void Afficher ()
void Afficher (unsigned int id)
string ToString ()
 Lister toutes le partie sous forme de string (envoi sur le réseau)
Les données sont séparées par des espaces, les parties par ':'.
int GetScorePacman (unsigned int id)
int SetScorePacman (unsigned int id, unsigned int score)
int GetScoreF (unsigned int id, unsigned int idFantome)
int SetScoreF (unsigned int id, unsigned int idFantome, unsigned int score)
string GetLoginPacman (unsigned int id)
int SetLoginPacman (unsigned int id, string login)
string GetLoginF (unsigned int id, unsigned int idFantome)
int SetLoginF (unsigned int id, unsigned int idFantome, string login)
int GetNbFantomeAuto (unsigned int id)
int SetNbFantomeAuto (unsigned int id, unsigned int nbFantomeAuto)

Private Member Functions

 Partie ()
 ~Partie ()

Private Attributes

TableauDyn< PartieInfomPartie
 Tableau gérant toutes les parties en cours.
Mutex mVerrou
 Mutex pour gérer les zones critiques.

Friends

class Singleton< Partie >

Detailed Description

Classe permettant de gérer les informations relatives aux parties
Cette classe est un singleton, elle peut donc être utilisée par plusieurs thread en même temps.


Les zones critiques sont protégés par un sémaphore d'exclusion mutuelle.

Definition at line 54 of file Partie.h.


Constructor & Destructor Documentation

Partie::Partie (  )  [inline, private]

Definition at line 57 of file Partie.h.

00057 {}

Partie::~Partie (  )  [inline, private]

Definition at line 58 of file Partie.h.

00058 {}


Member Function Documentation

int Partie::Rechercher ( unsigned int  id  ) 

Rechercher la position d'une partie dans le tableau.

Parameters:
id Le port TCP de la partie
Returns:
La position dans le tableau ou -1

Definition at line 214 of file Partie.cpp.

References TableauDyn< T >::Card(), Mutex::Lock(), mPartie, mVerrou, and Mutex::Unlock().

Referenced by Afficher(), AjouterPartie(), TraitementClient::CreerOuRejoindrePartie(), GetLoginF(), GetLoginPacman(), GetNbFantomeAuto(), GetScoreF(), GetScorePacman(), SetLoginF(), SetLoginPacman(), SetNbFantomeAuto(), SetScoreF(), SetScorePacman(), and SupprimerPartie().

00214                                      {
00215         mVerrou.Lock();
00216         for(unsigned int i=0; i<mPartie.Card(); i++){
00217                 if(mPartie[i].id==id) {
00218                         mVerrou.Unlock();
00219                         return i;
00220                 }
00221         }
00222         mVerrou.Unlock();
00223         return -1;
00224 }

Here is the call graph for this function:

int Partie::AjouterPartie ( unsigned int  id  ) 

Ajouter une partie au tableau (Le reste des infos est destiné a être renseigné plus tard).

Parameters:
id Le port TCP de la partie
Returns:
-1 en cas d'erreur

Definition at line 23 of file Partie.cpp.

References TableauDyn< T >::ConsQueue(), PartieInfo::id, Mutex::Lock(), PartieInfo::loginF, PartieInfo::loginP, mPartie, mVerrou, PartieInfo::nbFantomeAuto, PartieInfo::scoreF, PartieInfo::scoreP, and Mutex::Unlock().

Referenced by TraitementComServeurJeu::TraiterHello().

00023                                         {
00024         struct PartieInfo p;
00025         p.id=id;
00026         p.loginP="";
00027         p.scoreP=-1;
00028         p.nbFantomeAuto=-1;
00029         for(unsigned int i=0; i<3; i++){
00030                 p.scoreF[i]=-1; p.loginF[i]="";
00031         }
00032         mVerrou.Lock();
00033         mPartie.ConsQueue(p);
00034         mVerrou.Unlock();
00035 }

Here is the call graph for this function:

int Partie::AjouterPartie ( const PartieInfo p  ) 

Definition at line 37 of file Partie.cpp.

References TableauDyn< T >::ConsQueue(), PartieInfo::id, Mutex::Lock(), mPartie, mVerrou, Rechercher(), and Mutex::Unlock().

00037                                             {
00038         int pos=Rechercher(p.id);
00039         if(pos=-1) {
00040                 mVerrou.Lock();
00041                 mPartie.ConsQueue(p);
00042                 mVerrou.Unlock();
00043                 return 0;
00044         }
00045         return -1;
00046 }

Here is the call graph for this function:

int Partie::SupprimerPartie ( unsigned int  id  ) 

Supprimer une partir.

Parameters:
id Le port TCP de la partie
Returns:
-1 en cas d'erreur

Definition at line 48 of file Partie.cpp.

References TableauDyn< T >::Detruit(), Mutex::Lock(), mPartie, mVerrou, Rechercher(), and Mutex::Unlock().

Referenced by TraitementComServeurJeu::TraiterFinPartie().

00048                                            {
00049         int pos=Rechercher(id);
00050         if(pos!=-1) {
00051                 mVerrou.Lock();
00052                 mPartie.Detruit(pos);
00053                 mVerrou.Unlock();
00054                 return 0;
00055         }
00056         return -1;
00057 }

Here is the call graph for this function:

void Partie::Afficher (  ) 

Definition at line 89 of file Partie.cpp.

References TableauDyn< T >::Card(), and mPartie.

00089                      {
00090         for(unsigned int i=0; i<mPartie.Card(); i++){
00091                 Afficher(mPartie[i].id);
00092         }
00093 }

Here is the call graph for this function:

void Partie::Afficher ( unsigned int  id  ) 

Definition at line 95 of file Partie.cpp.

References PartieInfo::loginF, mPartie, Rechercher(), and PartieInfo::scoreF.

00095                                     {
00096         int pos=Rechercher(id);
00097         if(pos!=-1) {
00098                 cout<<"Partie sur le port "<<mPartie[pos].id<<" avec "<<mPartie[pos].nbFantomeAuto<<" fantomes automatiques"<<endl;
00099                 cout<<"\tPacman: "<<mPartie[pos].loginP<<" avec un score de "<<mPartie[pos].scoreP<<endl;
00100                 for(unsigned int i=0; i<3; i++){
00101                         cout<<"\tFantome "<<i<<": "<<mPartie[pos].loginF[i]<<" avec un score de "<<mPartie[pos].scoreF[i]<<endl;
00102                 }
00103         }
00104 }

Here is the call graph for this function:

string Partie::ToString (  ) 

Lister toutes le partie sous forme de string (envoi sur le réseau)
Les données sont séparées par des espaces, les parties par ':'.

Returns:
Port LoginP ScoreP LoginF[0..2] ScoreF[0..2] : etc...

Definition at line 59 of file Partie.cpp.

References TableauDyn< T >::Card(), PartieInfo::loginF, PartieInfo::loginP, mPartie, and PartieInfo::scoreF.

Referenced by TraitementClient::EnvoyerListePartie().

00059                        {
00060         string res="";
00061         for(unsigned int i=0; i<mPartie.Card(); i++){
00062                 ostringstream ossPort,ossScore, ossNBF;
00063                 ossPort<<mPartie[i].id;
00064                 string port=ossPort.str();
00065                 res+=port; res+=" ";
00066                 ossNBF<<mPartie[i].nbFantomeAuto;
00067                 string nbf=ossNBF.str();
00068                 res+=nbf; res+=" ";
00069                 if(mPartie[i].loginP!="") {
00070                         res+=mPartie[i].loginP; res+=" ";
00071                 } else res+="libre ";
00072                 ossScore<<mPartie[i].scoreP;
00073                 string score=ossScore.str();
00074                 res+=score; res+=" ";
00075                 for(unsigned int j=0; j<3; j++){
00076                         if(mPartie[i].loginF[j]!="") {
00077                                 res+=mPartie[i].loginF[j]; res+=" ";
00078                         } else res+="libre ";
00079                         ostringstream ossScoreF;
00080                         ossScoreF<<mPartie[i].scoreF[j];
00081                         string scoreF=ossScoreF.str();
00082                         res+=scoreF; res+=" ";
00083                 }
00084                 if(i<mPartie.Card()-1) res+=": ";
00085         }
00086         return res;
00087 }

Here is the call graph for this function:

int Partie::GetScorePacman ( unsigned int  id  ) 

Definition at line 106 of file Partie.cpp.

References mPartie, and Rechercher().

Referenced by TraitementComServeurJeu::TraiterFinPartie().

00106                                           {
00107         int pos=Rechercher(id);
00108         if(pos!=-1) {
00109                 return mPartie[pos].scoreP;
00110         }
00111         return -1;
00112 }

Here is the call graph for this function:

int Partie::SetScorePacman ( unsigned int  id,
unsigned int  score 
)

Definition at line 114 of file Partie.cpp.

References Mutex::Lock(), TableauDyn< T >::Modifier(), mPartie, mVerrou, Rechercher(), PartieInfo::scoreP, and Mutex::Unlock().

Referenced by TraitementComServeurJeu::TraiterConnexionJoueur(), and TraitementComServeurJeu::TraiterReceptionStatus().

00114                                                               {
00115         int pos=Rechercher(id);
00116         if(pos!=-1) {
00117                 struct PartieInfo p=mPartie[pos];
00118                 p.scoreP=score;
00119                 mVerrou.Lock();
00120                 mPartie.Modifier(pos,p);
00121                 mVerrou.Unlock();
00122                 return 0;
00123         }
00124         return -1;
00125 }

Here is the call graph for this function:

int Partie::GetScoreF ( unsigned int  id,
unsigned int  idFantome 
)

Definition at line 127 of file Partie.cpp.

References mPartie, and Rechercher().

Referenced by TraitementComServeurJeu::TraiterFinPartie().

00127                                                              {
00128         int pos=Rechercher(id);
00129         if(pos!=-1) {
00130                 return mPartie[pos].scoreF[idFantome];
00131         }
00132         return -1;
00133 }

Here is the call graph for this function:

int Partie::SetScoreF ( unsigned int  id,
unsigned int  idFantome,
unsigned int  score 
)

Definition at line 135 of file Partie.cpp.

References Mutex::Lock(), TableauDyn< T >::Modifier(), mPartie, mVerrou, Rechercher(), PartieInfo::scoreF, and Mutex::Unlock().

Referenced by TraitementComServeurJeu::TraiterConnexionJoueur(), and TraitementComServeurJeu::TraiterReceptionStatus().

00135                                                                                  {
00136         int pos=Rechercher(id);
00137         if(pos!=-1) {
00138                 struct PartieInfo p=mPartie[pos];
00139                 p.scoreF[idFantome]=score;
00140                 mVerrou.Lock();
00141                 mPartie.Modifier(pos,p);
00142                 mVerrou.Unlock();
00143                 return 0;
00144         }
00145         return -1;
00146 }

Here is the call graph for this function:

string Partie::GetLoginPacman ( unsigned int  id  ) 

Definition at line 161 of file Partie.cpp.

References mPartie, and Rechercher().

Referenced by TraitementComServeurJeu::TraiterFinPartie().

00161                                             {
00162         int pos=Rechercher(id);
00163         if(pos!=-1) {
00164                 return mPartie[pos].loginP;
00165         }
00166         return "";
00167 }

Here is the call graph for this function:

int Partie::SetLoginPacman ( unsigned int  id,
string  login 
)

Definition at line 148 of file Partie.cpp.

References Mutex::Lock(), PartieInfo::loginP, TableauDyn< T >::Modifier(), mPartie, mVerrou, Rechercher(), and Mutex::Unlock().

Referenced by TraitementComServeurJeu::TraiterConnexionJoueur().

00148                                                         {
00149         int pos=Rechercher(id);
00150         if(pos!=-1) {
00151                 struct PartieInfo p=mPartie[pos];
00152                 p.loginP=login;
00153                 mVerrou.Lock();
00154                 mPartie.Modifier(pos,p);
00155                 mVerrou.Unlock();
00156                 return 0;
00157         }
00158         return -1;
00159 }

Here is the call graph for this function:

string Partie::GetLoginF ( unsigned int  id,
unsigned int  idFantome 
)

Definition at line 183 of file Partie.cpp.

References mPartie, and Rechercher().

Referenced by TraitementComServeurJeu::TraiterFinPartie().

00183                                                                {
00184         int pos=Rechercher(id);
00185         if(pos!=-1) {
00186                 return mPartie[pos].loginF[idFantome];
00187         }
00188         return "";
00189 }

Here is the call graph for this function:

int Partie::SetLoginF ( unsigned int  id,
unsigned int  idFantome,
string  login 
)

Definition at line 169 of file Partie.cpp.

References Mutex::Lock(), PartieInfo::loginF, TableauDyn< T >::Modifier(), mPartie, mVerrou, Rechercher(), and Mutex::Unlock().

Referenced by TraitementComServeurJeu::TraiterConnexionJoueur().

00169                                                                           {
00170         int pos=Rechercher(id);
00171         if(pos!=-1) {
00172                 struct PartieInfo p=mPartie[pos];
00173                 p.loginF[idFantome]=login;
00174                 mVerrou.Lock();
00175                 mPartie.Modifier(pos,p);
00176                 mVerrou.Unlock();
00177                 return 0;
00178         }
00179         return -1;
00180 }

Here is the call graph for this function:

int Partie::GetNbFantomeAuto ( unsigned int  id  ) 

Definition at line 191 of file Partie.cpp.

References mPartie, and Rechercher().

00191                                            {
00192         int pos=Rechercher(id);
00193         if(pos!=-1) {
00194                 return mPartie[pos].nbFantomeAuto;
00195         }
00196         return -1;
00197 }

Here is the call graph for this function:

int Partie::SetNbFantomeAuto ( unsigned int  id,
unsigned int  nbFantomeAuto 
)

Definition at line 199 of file Partie.cpp.

References Mutex::Lock(), TableauDyn< T >::Modifier(), mPartie, mVerrou, PartieInfo::nbFantomeAuto, Rechercher(), and Mutex::Unlock().

Referenced by TraitementComServeurJeu::TraiterAttenteJoueur().

00199                                                                         {
00200         int pos=Rechercher(id);
00201         if(pos!=-1) {
00202                 struct PartieInfo p=mPartie[pos];
00203                 p.nbFantomeAuto=nbFantomeAuto;
00204                 mVerrou.Lock();
00205                 mPartie.Modifier(pos,p);
00206                 mVerrou.Unlock();
00207                 return 0;
00208         }
00209         return -1;
00210 }

Here is the call graph for this function:


Friends And Related Function Documentation

friend class Singleton< Partie > [friend]

Definition at line 55 of file Partie.h.


Member Data Documentation

TableauDyn<PartieInfo> Partie::mPartie [private]

Tableau gérant toutes les parties en cours.

Definition at line 103 of file Partie.h.

Referenced by Afficher(), AjouterPartie(), GetLoginF(), GetLoginPacman(), GetNbFantomeAuto(), GetScoreF(), GetScorePacman(), Rechercher(), SetLoginF(), SetLoginPacman(), SetNbFantomeAuto(), SetScoreF(), SetScorePacman(), SupprimerPartie(), and ToString().

Mutex Partie::mVerrou [private]

Mutex pour gérer les zones critiques.

Definition at line 108 of file Partie.h.

Referenced by AjouterPartie(), Rechercher(), SetLoginF(), SetLoginPacman(), SetNbFantomeAuto(), SetScoreF(), SetScorePacman(), and SupprimerPartie().


The documentation for this class was generated from the following files:
Generated on Wed Jan 2 14:02:08 2008 for Pacman by  doxygen 1.5.1