Skip to content

Commit

Permalink
got a potential structure going
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil Samith Bysani committed Jan 15, 2009
1 parent f6bbe48 commit 8db284f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 51 deletions.
22 changes: 11 additions & 11 deletions src/base/bang-module-api.c
Expand Up @@ -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);
}
54 changes: 30 additions & 24 deletions src/base/bang-module-api.h
Expand Up @@ -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;
Expand Down Expand Up @@ -39,66 +45,66 @@ 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;

/**
* \param The message you want to send to all peers.
*
* \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
* to identify you to peers running the module).
*
* 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.
Expand All @@ -110,22 +116,22 @@ 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.
*
* \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.
Expand All @@ -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
17 changes: 1 addition & 16 deletions src/base/bang-types.h
Expand Up @@ -32,7 +32,7 @@ typedef struct {
/**
* The module run method.
*/
void (*module_run)();
void (*module_run)(BANG_module_info);

/**
* The hash of the module.
Expand All @@ -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.
*/
Expand Down

0 comments on commit 8db284f

Please sign in to comment.