Add basic messaging support

git-svn-id: svn+ssh://cvs.lpds.sztaki.hu/var/lib/svn/szdg/dcapi/trunk@395 a7169a2c-3604-0410-bc95-c702d8d87f7a
This commit is contained in:
gombasg 2006-03-23 16:02:26 +00:00 committed by Adam Visegradi
parent e6c5d0afe7
commit d819db03fa
2 changed files with 68 additions and 3 deletions

View File

@ -40,7 +40,7 @@ int DC_init(void)
if (boinc_init())
return DC_ERR_INTERNAL;
if (!boinc_resolve_filename(CKPT_LABEL, path, sizeof(path)))
if (!boinc_resolve_filename(CKPT_LABEL_IN, path, sizeof(path)))
last_complete_ckpt = strdup(path);
ret = stat("init_data.xml", &st);
@ -51,7 +51,7 @@ int DC_init(void)
if (!f)
return DC_ERR_INTERNAL;
buf = malloc(st.st_size + 1);
buf = (char *)malloc(st.st_size + 1);
fread(buf, st.st_size, 1, f);
fclose(f);
buf[st.st_size] = '\0';
@ -101,13 +101,58 @@ int DC_sendResult(const char *logicalFileName, const char *path,
return DC_ERR_NOTIMPL;
}
static void handle_special_msg(const char *message)
{
/* XXX Implement it */
}
DC_Event DC_checkEvent(void **data)
{
char *buf;
*data = NULL;
/* Check for checkpoint requests */
if (boinc_time_to_checkpoint())
return DC_EVENT_DO_CHECKPOINT;
/* Check for messages */
buf = (char *)malloc(MAX_MESSAGE_SIZE);
if (buf)
{
int ret;
ret = boinc_receive_trickle_down(buf, MAX_MESSAGE_SIZE);
if (ret)
{
if (!strncmp(buf, DCAPI_MSG_PFX, strlen(DCAPI_MSG_PFX)))
{
handle_special_msg(buf);
free(buf);
return DC_EVENT_NONE;
}
*data = buf;
return DC_EVENT_MESSAGE;
}
free(buf);
}
return DC_EVENT_NONE;
}
void DC_destroyEvent(DC_Event event, void *data)
{
switch (event)
{
case DC_EVENT_MESSAGE:
free(data);
break;
default:
break;
}
}
void DC_checkpointMade(const char *filename)
{
boinc_checkpoint_completed();
@ -125,6 +170,16 @@ void DC_finish(int exitcode)
boinc_finish(exitcode);
}
int DC_sendMessage(const char *message)
{
return boinc_send_trickle_up(wu_name, (char *)message);
}
int DC_getMaxMessageSize(void)
{
return MAX_MESSAGE_SIZE;
}
/********************************************************************
* Provide empty implementation for some functions required by the
* BOINC libraries

View File

@ -6,8 +6,18 @@
extern "C" {
#endif
/* Prefix of subresult file labels */
#define SUBRESULT_PFX "_dc_subresult_"
#define CKPT_LABEL "_dc_checkpoint"
/* Logical names of the checkpoint file */
#define CKPT_LABEL_IN "_dc_checkpoint_in"
#define CKPT_LABEL_OUT "_dc_checkpoint_out"
/* Maximum allowed message length */
#define MAX_MESSAGE_SIZE 16384
/* Prefix for internal messages between the client-side and master-side DC-API */
#define DCAPI_MSG_PFX "__dcapi__"
#ifdef __cplusplus
}