diff --git a/src/base/bang-module-api.c b/src/base/bang-module-api.c index 81a02b6..4898e43 100644 --- a/src/base/bang-module-api.c +++ b/src/base/bang-module-api.c @@ -10,38 +10,38 @@ #include"bang-module-api.h" /* TODO: Implement this. Well, this is basically what are our app is all about. */ -void BANG_debug_on_all_peers(char *message) { +void BANG_debug_on_all_peers(BANG_module_info *info, char *message) { fprintf(stderr,message); } -void BANG_get_me_peers() { +void BANG_get_me_peers(BANG_module_info *info) { } -int BANG_number_of_active_peers() { - return 1; +int BANG_number_of_active_peers(BANG_module_info *info) { + return info->peer_number; } -int BANG_get_my_id() { - return 0; +int BANG_get_my_id(BANG_module_info *info) { + return info->my_id; } -void BANG_assert_authority(int id) { +void BANG_assert_authority(BANG_module_info *info, int id) { fprintf(stderr,"%d is asserting authority!\n",id); } -void BANG_assert_authority_to_peer(int authority, int peer) { +void BANG_assert_authority_to_peer(BANG_module_info *info, int authority, int peer) { fprintf(stderr,"%d is asserting authority to %d!\n",authority,peer); } -BANG_job* BANG_request_job(int id, char blocking) { +BANG_job* BANG_request_job(BANG_module_info *info, int id, char blocking) { fprintf(stderr,"Requesting a job from authority %d with blocking at %d!\n",id,blocking); return NULL; } -void BANG_finished_request(BANG_job *job) { +void BANG_finished_request(BANG_module_info *info, BANG_job *job) { fprintf(stderr,"Finished job for authority %d!\n",job->authority); } -void BANG_send_job( BANG_job *job) { +void BANG_send_job(BANG_module_info *info, BANG_job *job) { fprintf(stderr,"Sending job to %d by authority %d!\n",job->peer,job->authority); } diff --git a/src/base/bang-module-api.h b/src/base/bang-module-api.h index fed52e3..39e3ead 100644 --- a/src/base/bang-module-api.h +++ b/src/base/bang-module-api.h @@ -10,6 +10,12 @@ #ifndef __BANG_MODULE_API_H #define __BANG_MODULE_API_H +typedef struct { + int *peers; + int peer_number; + int my_id; +} BANG_module_info; + typedef struct { void *data; unsigned int length; @@ -39,32 +45,32 @@ typedef struct { * Callback for when jobs are available for you to request * \param int The id of the peer with jobs available. */ - void (*jobs_available) (int); + void (*jobs_available) (BANG_module_info*, int); /** * Callback for when a finished job is sent to you. * \param BANG_job* The job that has been finished. */ - void (*jobs_done) (BANG_job*); + void (*jobs_done) (BANG_module_info*, BANG_job*); /** * Callback for when a peer requests you a job from you. * \param int The id of peer requesting a job. */ - void (*outgoing_job) (int); + void (*outgoing_job) (BANG_module_info*, int); /** * Callback for when a job is sent to you. * \param BANG_job* the job that is sent to you. */ - void (*incoming_job) (BANG_job*); + void (*incoming_job) (BANG_module_info*, BANG_job*); /** * Callback for when a peer is added. * \param int The id of the added peer. */ - void (*peer_added) (int); + void (*peer_added) (BANG_module_info*, int); /** * Callback for when a peer is removed. * \param int The id of the removed peer. */ - void (*peer_removed) (int); + void (*peer_removed) (BANG_module_info*, int); } BANG_callbacks; /** @@ -72,18 +78,18 @@ typedef struct { * * \brief Prints a debugging message on all peers. */ -void BANG_debug_on_all_peers(char *message); +void BANG_debug_on_all_peers(BANG_module_info *info, char *message); /** * \brief Tries to get a module as many peers as possible. */ -void BANG_get_me_peers(); +void BANG_get_me_peers(BANG_module_info *info); /** - * \return Returns the number of peers currently active. (Peers being peers + *\return Returns the number of peers currently active. (Peers being peers * who are running your module. */ -int BANG_number_of_active_peers(); +int BANG_number_of_active_peers(BANG_module_info *info); /** * \return Returns your peer number. (This is not a peer_id, it is a number @@ -91,14 +97,14 @@ int BANG_number_of_active_peers(); * * Discussion: Should this number be passed to the init function? */ -int BANG_get_my_id(); +int BANG_get_my_id(BANG_module_info *info); /** * \brief Tells all your peers that peer id has a job waiting. */ -void BANG_assert_authority(int id); +void BANG_assert_authority(BANG_module_info *info, int id); -void BANG_assert_authority_to_peer(int authority, int peer); +void BANG_assert_authority_to_peer(BANG_module_info *info, int authority, int peer); /** * \param id The peer to get a job from. @@ -110,7 +116,7 @@ void BANG_assert_authority_to_peer(int authority, int peer); * Else, an error or non blocking happened. * */ -BANG_job* BANG_request_job(int id, char blocking); +BANG_job *BANG_request_job(BANG_module_info *info, int id, char blocking); /** * \param job The finished job. @@ -118,14 +124,14 @@ BANG_job* BANG_request_job(int id, char blocking); * \brief Sends the job to the peer. If the peer is you, * it will send it to your callback method. */ -void BANG_finished_request(BANG_job *job); +void BANG_finished_request(BANG_module_info *info, BANG_job *job); /** * \param The peer to send your the job to. * * \brief Sends a job to a peer. */ -void BANG_send_job(BANG_job *job); +void BANG_send_job(BANG_module_info *info, BANG_job *job); /** * The api for the modules to use. @@ -134,14 +140,14 @@ typedef struct { /** * Reference to BANG_debug_on_all_peers. */ - void (*BANG_debug_on_all_peers) (char *message); - void (*BANG_get_me_peers) (); + void (*BANG_debug_on_all_peers) (BANG_module_info *info, char *message); + void (*BANG_get_me_peers) (BANG_module_info *info); int (*BANG_number_of_active_peers) (); - int (*BANG_get_my_id) (); - void (*BANG_assert_authority) (int id); - void (*BANG_assert_authority_to_peer) (int authority, int peer); - BANG_job* (*BANG_request_job) (int id, char blocking); - void (*BANG_finished_request) (BANG_job *job); - void (*BANG_send_job) (BANG_job *job); + int (*BANG_get_my_id) (BANG_module_info *info); + void (*BANG_assert_authority) (BANG_module_info *info, int id); + void (*BANG_assert_authority_to_peer) (BANG_module_info *info, int authority, int peer); + BANG_job* (*BANG_request_job) (BANG_module_info *info, int id, char blocking); + void (*BANG_finished_request) (BANG_module_info *info, BANG_job *job); + void (*BANG_send_job) (BANG_module_info *info, BANG_job *job); } BANG_api; #endif diff --git a/src/base/bang-types.h b/src/base/bang-types.h index 2cbe784..d9124de 100644 --- a/src/base/bang-types.h +++ b/src/base/bang-types.h @@ -32,7 +32,7 @@ typedef struct { /** * The module run method. */ - void (*module_run)(); + void (*module_run)(BANG_module_info); /** * The hash of the module. @@ -50,21 +50,6 @@ typedef struct { char *path; } BANG_module; -typedef struct { - int *peer_ids; - unsigned int num_peers; -} BANG_module_peerset; - -typedef struct { - BANG_module *module; - BANG_module_peerset *peers; -} BANG_module_register; - -typedef struct { - BANG_module_register *registery; - unsigned int length; -} BANG_module_registery; - /** * This is the structure that is sent to each signal handler. */