Freeciv-3.1
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
agents.c File Reference
#include <stdarg.h>
#include <string.h>
#include "capability.h"
#include "log.h"
#include "mem.h"
#include "timing.h"
#include "client_main.h"
#include "mapctrl_g.h"
#include "cma_core.h"
#include "cma_fec.h"
#include "sha.h"
#include "agents.h"
#include "speclist.h"

Go to the source code of this file.

Data Structures

struct  call
 

Macros

#define log_request_ids(...)   /* log_test(__VA_ARGS__) */
 
#define log_todo_lists(...)   /* log_test(__VA_ARGS__) */
 
#define log_meta_callback(...)   log_debug(__VA_ARGS__)
 
#define log_debug_freeze(...)   /* log_test(__VA_ARGS__) */
 
#define MAX_AGENTS   10
 
#define SPECLIST_TAG   call
 
#define SPECLIST_TYPE   struct call
 
#define call_list_iterate(calllist, pcall)    TYPED_LIST_ITERATE(struct call, calllist, pcall)
 
#define call_list_iterate_end   LIST_ITERATE_END
 
#define call_list_both_iterate(calllist, plink, pcall)
 
#define call_list_both_iterate_end   LIST_BOTH_ITERATE_END
 

Functions

static bool calls_are_equal (const struct call *pcall1, const struct call *pcall2)
 
static void enqueue_call (enum oct type, enum callback_type cb_type, struct my_agent *agent,...)
 
static struct callremove_and_return_a_call (void)
 
static void execute_call (const struct call *call)
 
static void call_handle_methods (void)
 
static void freeze (void)
 
static void thaw (void)
 
static struct my_agent * agent_by_name (const char *agent_name)
 
static bool is_outstanding_request (struct my_agent *agent)
 
void agents_init (void)
 
void agents_free (void)
 
void register_agent (const struct agent *agent)
 
void agents_disconnect (void)
 
void agents_processing_started (void)
 
void agents_processing_finished (void)
 
void agents_freeze_hint (void)
 
void agents_thaw_hint (void)
 
void agents_game_joined (void)
 
void agents_game_start (void)
 
void agents_before_new_turn (void)
 
void agents_start_turn (void)
 
void agents_new_turn (void)
 
void agents_unit_changed (struct unit *punit)
 
void agents_unit_new (struct unit *punit)
 
void agents_unit_remove (struct unit *punit)
 
void agents_city_changed (struct city *pcity)
 
void agents_city_new (struct city *pcity)
 
void agents_city_remove (struct city *pcity)
 
void agents_tile_remove (struct tile *ptile)
 
void agents_tile_changed (struct tile *ptile)
 
void agents_tile_new (struct tile *ptile)
 
void wait_for_requests (const char *agent_name, int first_request_id, int last_request_id)
 
void cause_a_unit_changed_for_agent (const char *name_of_calling_agent, struct unit *punit)
 
void cause_a_city_changed_for_agent (const char *name_of_calling_agent, struct city *pcity)
 
bool agents_busy (void)
 

Variables

struct { 
 
   int   entries_used 
 
   struct my_agent
 
      struct agent   agent 
 
      int   first_outstanding_request_id 
 
      int   last_outstanding_request_id 
 
      struct { 
 
         struct timer *   network_wall_timer 
 
         int   wait_at_network 
 
         int   wait_at_network_requests 
 
      }   stats 
 
   }   entries [MAX_AGENTS
 
   struct call_list *   calls 
 
agents 
 
static bool initialized = FALSE
 
static int frozen_level
 
static bool currently_running = FALSE
 

Macro Definition Documentation

◆ call_list_both_iterate

#define call_list_both_iterate (   calllist,
  plink,
  pcall 
)
Value:
TYPED_LIST_BOTH_ITERATE(struct call_list_link, struct call, \
calllist, plink, pcall)
#define TYPED_LIST_BOTH_ITERATE(TYPE_link, TYPE_data, ARG_list, NAME_link, NAME_data)
Definition speclist.h:698
Definition agents.c:49

Definition at line 64 of file agents.c.

◆ call_list_both_iterate_end

#define call_list_both_iterate_end   LIST_BOTH_ITERATE_END

Definition at line 67 of file agents.c.

◆ call_list_iterate

#define call_list_iterate (   calllist,
  pcall 
)     TYPED_LIST_ITERATE(struct call, calllist, pcall)

Definition at line 60 of file agents.c.

◆ call_list_iterate_end

#define call_list_iterate_end   LIST_ITERATE_END

Definition at line 62 of file agents.c.

◆ log_debug_freeze

#define log_debug_freeze (   ...)    /* log_test(__VA_ARGS__) */

Definition at line 43 of file agents.c.

◆ log_meta_callback

#define log_meta_callback (   ...)    log_debug(__VA_ARGS__)

Definition at line 42 of file agents.c.

◆ log_request_ids

#define log_request_ids (   ...)    /* log_test(__VA_ARGS__) */

Definition at line 40 of file agents.c.

◆ log_todo_lists

#define log_todo_lists (   ...)    /* log_test(__VA_ARGS__) */

Definition at line 41 of file agents.c.

◆ MAX_AGENTS

#define MAX_AGENTS   10

Definition at line 45 of file agents.c.

◆ SPECLIST_TAG

#define SPECLIST_TAG   call

Definition at line 56 of file agents.c.

◆ SPECLIST_TYPE

#define SPECLIST_TYPE   struct call

Definition at line 57 of file agents.c.

Function Documentation

◆ agent_by_name()

static struct my_agent * agent_by_name ( const char *  agent_name)
static

Helper.

Definition at line 296 of file agents.c.

Referenced by cause_a_city_changed_for_agent(), cause_a_unit_changed_for_agent(), and wait_for_requests().

◆ agents_before_new_turn()

void agents_before_new_turn ( void  )

Called from client/packhand.c.

Definition at line 462 of file agents.c.

Referenced by handle_end_turn().

◆ agents_busy()

bool agents_busy ( void  )

Returns TRUE iff some agent is currently busy.

Definition at line 799 of file agents.c.

Referenced by can_end_turn(), and send_turn_done().

◆ agents_city_changed()

void agents_city_changed ( struct city pcity)

Called from client/packhand.c. See agents_unit_changed() for a generic documentation.

Definition at line 584 of file agents.c.

Referenced by handle_city_info(), and handle_city_short_info().

◆ agents_city_new()

void agents_city_new ( struct city pcity)

Called from client/packhand.c. See agents_unit_changed() for a generic documentation.

Definition at line 610 of file agents.c.

Referenced by handle_city_info(), and handle_city_short_info().

◆ agents_city_remove()

void agents_city_remove ( struct city pcity)

Called from client/packhand.c. See agents_unit_changed() for a generic documentation.

Definition at line 636 of file agents.c.

Referenced by handle_city_remove().

◆ agents_disconnect()

void agents_disconnect ( void  )

Called from client/packhand.c.

Definition at line 400 of file agents.c.

Referenced by set_client_state().

◆ agents_free()

void agents_free ( void  )

Free resources allocated for agents framework

Definition at line 346 of file agents.c.

Referenced by client_game_free(), and client_game_reset().

◆ agents_freeze_hint()

void agents_freeze_hint ( void  )

Called from client/packhand.c.

Definition at line 427 of file agents.c.

Referenced by handle_freeze_client(), and input_from_server().

◆ agents_game_joined()

void agents_game_joined ( void  )

Called from client/packhand.c.

Definition at line 445 of file agents.c.

Referenced by handle_server_join_reply().

◆ agents_game_start()

void agents_game_start ( void  )

Called from client/packhand.c.

Definition at line 453 of file agents.c.

Referenced by set_client_state().

◆ agents_init()

void agents_init ( void  )

Called once per client startup.

Definition at line 332 of file agents.c.

Referenced by client_game_init(), and client_game_reset().

◆ agents_new_turn()

void agents_new_turn ( void  )

Called from client/packhand.c. See agents_unit_changed() for a generic documentation.

Definition at line 479 of file agents.c.

Referenced by handle_new_year().

◆ agents_processing_finished()

void agents_processing_finished ( void  )

Called from client/packhand.c.

Definition at line 418 of file agents.c.

Referenced by handle_processing_finished().

◆ agents_processing_started()

void agents_processing_started ( void  )

Called from client/packhand.c.

Definition at line 409 of file agents.c.

Referenced by handle_processing_started().

◆ agents_start_turn()

void agents_start_turn ( void  )

Called from client/packhand.c.

Definition at line 470 of file agents.c.

Referenced by handle_start_phase().

◆ agents_thaw_hint()

void agents_thaw_hint ( void  )

Called from client/packhand.c.

Definition at line 436 of file agents.c.

Referenced by handle_thaw_client(), and input_from_server().

◆ agents_tile_changed()

void agents_tile_changed ( struct tile ptile)

Called from client/packhand.c. See agents_unit_changed() for a generic documentation.

Definition at line 687 of file agents.c.

Referenced by handle_tile_info().

◆ agents_tile_new()

void agents_tile_new ( struct tile ptile)

Called from client/packhand.c. See agents_unit_changed() for a generic documentation.

Definition at line 711 of file agents.c.

Referenced by handle_tile_info().

◆ agents_tile_remove()

void agents_tile_remove ( struct tile ptile)

Called from client/packhand.c. See agents_unit_changed() for a generic documentation. Tiles got removed because of FOW.

Definition at line 663 of file agents.c.

Referenced by handle_tile_info().

◆ agents_unit_changed()

void agents_unit_changed ( struct unit punit)

Called from client/packhand.c. A call is created and added to the list of outstanding calls if an agent wants to be informed about this event and the change wasn't caused by the agent. We then try (this may not be successful in every case since we can be frozen or another call_handle_methods may be running higher up on the stack) to execute all outstanding calls.

Definition at line 507 of file agents.c.

Referenced by handle_unit_packet_common().

◆ agents_unit_new()

void agents_unit_new ( struct unit punit)

Called from client/packhand.c. See agents_unit_changed() for a generic documentation.

Definition at line 532 of file agents.c.

Referenced by handle_unit_packet_common().

◆ agents_unit_remove()

void agents_unit_remove ( struct unit punit)

Called from client/packhand.c. See agents_unit_changed() for a generic documentation.

Definition at line 558 of file agents.c.

Referenced by handle_unit_remove().

◆ call_handle_methods()

static void call_handle_methods ( void  )
static

Execute all outstanding calls. This method will do nothing if the dispatching is frozen (frozen_level > 0). Also call_handle_methods will ensure that only one instance is running at any given time.

Definition at line 235 of file agents.c.

Referenced by agents_city_changed(), agents_city_new(), agents_city_remove(), agents_game_start(), agents_tile_changed(), agents_tile_new(), agents_tile_remove(), agents_unit_changed(), agents_unit_new(), agents_unit_remove(), cause_a_city_changed_for_agent(), cause_a_unit_changed_for_agent(), and thaw().

◆ calls_are_equal()

static bool calls_are_equal ( const struct call pcall1,
const struct call pcall2 
)
static

Return TRUE iff the two agent calls are equal.

Definition at line 93 of file agents.c.

Referenced by enqueue_call().

◆ cause_a_city_changed_for_agent()

void cause_a_city_changed_for_agent ( const char *  name_of_calling_agent,
struct city pcity 
)

Adds a specific call for the given agent.

Definition at line 786 of file agents.c.

Referenced by cma_put_city_under_agent().

◆ cause_a_unit_changed_for_agent()

void cause_a_unit_changed_for_agent ( const char *  name_of_calling_agent,
struct unit punit 
)

Adds a specific call for the given agent.

Definition at line 773 of file agents.c.

◆ enqueue_call()

static void enqueue_call ( enum oct  type,
enum callback_type  cb_type,
struct my_agent *  agent,
  ... 
)
static

If the call described by the given arguments isn't contained in agents.calls list, add the call to this list. Maintains the list in a sorted order.

Definition at line 122 of file agents.c.

Referenced by agents_city_changed(), agents_city_new(), agents_city_remove(), agents_new_turn(), agents_tile_changed(), agents_tile_new(), agents_tile_remove(), agents_unit_changed(), agents_unit_new(), agents_unit_remove(), cause_a_city_changed_for_agent(), and cause_a_unit_changed_for_agent().

◆ execute_call()

static void execute_call ( const struct call call)
static

Calls an callback of an agent as described in the given call.

Definition at line 211 of file agents.c.

Referenced by call_handle_methods().

◆ freeze()

static void freeze ( void  )
static

Increase the frozen_level by one.

Definition at line 269 of file agents.c.

Referenced by agents_freeze_hint(), and agents_processing_started().

◆ is_outstanding_request()

static bool is_outstanding_request ( struct my_agent *  agent)
static

Returns TRUE iff currently handled packet was caused by the given agent.

Definition at line 312 of file agents.c.

Referenced by agents_city_changed(), agents_city_new(), agents_city_remove(), agents_new_turn(), agents_tile_changed(), agents_tile_new(), agents_tile_remove(), agents_unit_changed(), agents_unit_new(), and agents_unit_remove().

◆ register_agent()

void register_agent ( const struct agent agent)

Registers an agent.

Definition at line 378 of file agents.c.

Referenced by cma_init(), cmafec_init(), and simple_historian_init().

◆ remove_and_return_a_call()

static struct call * remove_and_return_a_call ( void  )
static

Return an outstanding call. The call is removed from the agents.calls list. Returns NULL if there no more outstanding calls.

Definition at line 193 of file agents.c.

Referenced by agents_free(), and call_handle_methods().

◆ thaw()

static void thaw ( void  )
static

Decrease the frozen_level by one. If the dispatching is not frozen anymore (frozen_level == 0) all outstanding calls are executed.

Definition at line 283 of file agents.c.

Referenced by agents_processing_finished(), and agents_thaw_hint().

◆ wait_for_requests()

void wait_for_requests ( const char *  agent_name,
int  first_request_id,
int  last_request_id 
)

Called from an agent. This function will return until the last request has been processed by the server.

Definition at line 735 of file agents.c.

Referenced by apply_result_on_server().

Variable Documentation

◆ agent

struct agent agent

Definition at line 76 of file agents.c.

Referenced by enqueue_call().

◆ [struct]

struct { ... } agents

◆ calls

struct call_list* calls

Definition at line 83 of file agents.c.

◆ currently_running

bool currently_running = FALSE
static

Definition at line 88 of file agents.c.

Referenced by agents_busy(), and call_handle_methods().

◆ [struct]

struct { ... } ::my_agent entries[MAX_AGENTS]

◆ entries_used

int entries_used

◆ first_outstanding_request_id

int first_outstanding_request_id

Definition at line 77 of file agents.c.

◆ frozen_level

int frozen_level
static

Definition at line 87 of file agents.c.

Referenced by agents_busy(), call_handle_methods(), freeze(), and thaw().

◆ initialized

bool initialized = FALSE
static

Definition at line 86 of file agents.c.

Referenced by agents_busy(), agents_disconnect(), and freeze().

◆ last_outstanding_request_id

int last_outstanding_request_id

Definition at line 77 of file agents.c.

◆ network_wall_timer

struct timer* network_wall_timer

Definition at line 79 of file agents.c.

◆ [struct]

struct { ... } stats

Referenced by script_server_load_file().

◆ wait_at_network

int wait_at_network

Definition at line 80 of file agents.c.

◆ wait_at_network_requests

int wait_at_network_requests

Definition at line 80 of file agents.c.