GoData

Name

GoData -- the database for the golist classes

Synopsis


#include <go-data.h>


void        (*go_cb)                        (GtkObject *obj,
                                             void *client_data);
struct      GoData;
GtkObject*  go_data_new                     (void);
gboolean    go_data_load                    (GoData *self,
                                             const gchar *filename);
gboolean    go_data_save                    (GoData *self,
                                             const gchar *filename);
void        go_data_clear                   (GoData *self);
void        go_data_notify_games_changed    (GoData *self);
void        go_data_notify_players_changed  (GoData *self);

void        go_data_add_client              (GoData *self,
                                             GoClient *client);
void        go_data_remove_client           (GoData *self,
                                             GoClient *client);

void        go_data_add_player              (GoData *self,
                                             GoPlayer *player);
void        go_data_remove_player           (GoData *self,
                                             GoPlayer *player);
void        go_data_player_lock             (GoData *self,
                                             GoPlayer *p);
void        go_data_player_unlock           (GoData *self,
                                             GoPlayer *p);
int         go_data_player_count            (GoData *self);
GList*      go_data_player_tokens           (GoData *self);
GoPlayer*   go_data_find_token              (GoData *self,
                                             const char *token);
int         go_data_player_game_count       (GoData *self,
                                             GoPlayer *player);
int         go_data_player_win_count        (GoData *self,
                                             GoPlayer *player);
int         go_data_player_game_index       (GoData *self,
                                             GoPlayer *player,
                                             GoGame *game);
int         go_data_player_component        (GoData *self,
                                             const GoPlayer *player);
gboolean    go_data_players_equiv           (GoData *self,
                                             const GoPlayer *a,
                                             const GoPlayer *b);

void        go_data_add_game                (GoData *self,
                                             GoGame *game);
void        go_data_remove_game             (GoData *self,
                                             GoGame *game);
void        go_data_game_lock               (GoData *self,
                                             GoGame *g);
void        go_data_game_unlock             (GoData *self,
                                             GoGame *g);
int         go_data_game_count              (GoData *self);

Object Hierarchy


  GtkObject
   +----GoData

Signal Prototypes


"changed"   void        user_function      (GoData *godata,
                                            gpointer user_data);

Description

The GoData class implements a simple database. It holds all the data, both about the players and about the games. An arbitrary number of clients (i.e. Objects derived from GoClient) may connect to a GoData object.

You may add players of games to the database with the help of the go_data_add_player() and go_data_add_game() functions. To query or modify the contents of the database use client objects (i.e. objects of a subclass of GoClient).

Details

go_cb ()

void        (*go_cb)                        (GtkObject *obj,
                                             void *client_data);

obj : 
client_data : 


struct GoData

struct GoData;

The GoData structure has no public fields.


go_data_new ()

GtkObject*  go_data_new                     (void);

Allocate a new, empty GoData object.

Returns : a newly allocated GoData object.


go_data_load ()

gboolean    go_data_load                    (GoData *self,
                                             const gchar *filename);

Loads the golist XML file denoted by filename into the GoData object self.

self : a GoData object
filename : the file to load
Returns : TRUE, iff the file was loaded successfully, and FALSE if the file cannot be read or is no golist XML file.


go_data_save ()

gboolean    go_data_save                    (GoData *self,
                                             const gchar *filename);

Dumps the GoData object self into the golist XML file filename.

self : a GoData object
filename : the file to save
Returns : TRUE, iff the file was saved successfully, and FALSE if the file cannot be written.


go_data_clear ()

void        go_data_clear                   (GoData *self);

Remove all entries from the database. The corresponding GoGame and GoPlayer objects are destroyed.

self : a GoData object


go_data_notify_games_changed ()

void        go_data_notify_games_changed    (GoData *self);

This must be called in order to propagate changes to the game list. It updates all clients and emits the "changed" signal.

self : a GoData object


go_data_notify_players_changed ()

void        go_data_notify_players_changed  (GoData *self);

This must be called in order to propagate changes to the player list. It updates all clients and emits the "changed" signal.

self : a GoData object


go_data_add_client ()

void        go_data_add_client              (GoData *self,
                                             GoClient *client);

Register a new client of this GoData.

self : a GoData object
client : a GoClient object


go_data_remove_client ()

void        go_data_remove_client           (GoData *self,
                                             GoClient *client);

Disconnect the client from the GoData object.

self : a GoData object
client : a GoClient object


go_data_add_player ()

void        go_data_add_player              (GoData *self,
                                             GoPlayer *player);

Register a new player of this GoData and update all clients.

self : a GoData object
player : a GoPlayer object


go_data_remove_player ()

void        go_data_remove_player           (GoData *self,
                                             GoPlayer *player);

Disconnect the player from the GoData object and update all clients.

self : a GoData object
player : a GoPlayer object


go_data_player_lock ()

void        go_data_player_lock             (GoData *self,
                                             GoPlayer *p);

This function must be called before p is modified. After you are done with p you must call player_unlock() to propagate the changes.

self : a GoData object
p : the player to modify


go_data_player_unlock ()

void        go_data_player_unlock           (GoData *self,
                                             GoPlayer *p);

Undo the effects of player_lock() and update the clients.

self : a GoData object
p : the modified player


go_data_player_count ()

int         go_data_player_count            (GoData *self);

Determine the number of players in the database.

self : the GoData object
Returns : the number of known players.


go_data_player_tokens ()

GList*      go_data_player_tokens           (GoData *self);

Return the list of all player tokens. The returned list must not be freed of modified. It becomes invalid if the player list of self is modified.

self : a GoData object
Returns : the list of all player tokens


go_data_find_token ()

GoPlayer*   go_data_find_token              (GoData *self,
                                             const char *token);

Get the player denoted by token.

self : a GoData object
token : a player token
Returns : a pointer to the player struct or NULL if token is invalid.


go_data_player_game_count ()

int         go_data_player_game_count       (GoData *self,
                                             GoPlayer *player);

Get the number of games recorded for player.

self : a GoData object
player : a GoPlayer object
Returns : the number of games


go_data_player_win_count ()

int         go_data_player_win_count        (GoData *self,
                                             GoPlayer *player);

Get the number of won games recorded for player.

self : a GoData object
player : a GoPlayer object
Returns : the number of won games


go_data_player_game_index ()

int         go_data_player_game_index       (GoData *self,
                                             GoPlayer *player,
                                             GoGame *game);

Return the number of games in the data base self, which involve player and are played before game. So, if the function returns n this indicates that game is the n-th game recorded for player.

self : a GoData object
player : a GoPlayer object
game : a GoGame object
Returns : the index of game for player


go_data_player_component ()

int         go_data_player_component        (GoData *self,
                                             const GoPlayer *player);

Calculate the index for the connected component of player within the game graph. The value 0 indicates the component of players of defined rank.

self : a GoData object
player : the player to calculate the component for
Returns : the component index


go_data_players_equiv ()

gboolean    go_data_players_equiv           (GoData *self,
                                             const GoPlayer *a,
                                             const GoPlayer *b);

self : a GoData object
a : the first player
b : the second player
Returns : TRUE if a and b are in the same connected component of the game graph


go_data_add_game ()

void        go_data_add_game                (GoData *self,
                                             GoGame *game);

Register a new game for this GoData object and update all clients.

self : a GoData object
game : a GoGame object


go_data_remove_game ()

void        go_data_remove_game             (GoData *self,
                                             GoGame *game);

Disconnect the game from the GoData object and update all clients.

self : a GoData object
game : a GoGame object


go_data_game_lock ()

void        go_data_game_lock               (GoData *self,
                                             GoGame *g);

This function must be called before g is modified. After you are done with g you must call game_unlock() to propagate the changes.

self : a GoData object
g : the game to modify


go_data_game_unlock ()

void        go_data_game_unlock             (GoData *self,
                                             GoGame *g);

Undo the effects of game_lock() and update the clients.

self : a GoData object
g : the modified game


go_data_game_count ()

int         go_data_game_count              (GoData *self);

Determine the number of games in the database.

self : the GoData object
Returns : the number of known games.

Signals

The "changed" signal

void        user_function                  (GoData *godata,
                                            gpointer user_data);

godata :the object which received the signal.
user_data :user data set when the signal handler was connected.

See Also

GoClient