mirror of https://github.com/BOINC/boinc.git
106 lines
2.0 KiB
C
106 lines
2.0 KiB
C
#ifdef HAVE_CONFIG_H
|
|
#include <config.h>
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <glib.h>
|
|
|
|
#include "dc_local.h"
|
|
|
|
/********************************************************************
|
|
* Global variables
|
|
*/
|
|
|
|
DC_ResultCallback _dc_resultcb;
|
|
DC_SubresultCallback _dc_subresultcb;
|
|
DC_MessageCallback _dc_messagecb;
|
|
|
|
char project_uuid_str[37];
|
|
uuid_t project_uuid;
|
|
int sleep_interval;
|
|
|
|
/********************************************************************
|
|
* API functions
|
|
*/
|
|
|
|
int DC_initMaster(const char *config_file)
|
|
{
|
|
char *cfgval;
|
|
int ret;
|
|
|
|
if (!config_file)
|
|
config_file = DC_CONFIG_FILE;
|
|
|
|
ret = _DC_parseCfg(config_file);
|
|
if (ret)
|
|
{
|
|
DC_log(LOG_ERR, "The DC-API cannot be initialized without a "
|
|
"config file");
|
|
return ret;
|
|
}
|
|
|
|
/* Check the working directory */
|
|
cfgval = DC_getCfgStr(CFG_WORKDIR);
|
|
if (!cfgval)
|
|
{
|
|
DC_log(LOG_ERR, "%s is not specified in the config file",
|
|
CFG_WORKDIR);
|
|
return DC_ERR_CONFIG;
|
|
}
|
|
free(cfgval);
|
|
|
|
/* Check sleep interval */
|
|
sleep_interval = DC_getCfgInt(CFG_SLEEPINTERVAL, DEFAULT_SLEEP_INTERVAL);
|
|
if (sleep_interval < 1)
|
|
sleep_interval = 1;
|
|
|
|
/* Check the project UUID */
|
|
cfgval = DC_getCfgStr(CFG_INSTANCEUUID);
|
|
if (!cfgval)
|
|
{
|
|
DC_log(LOG_ERR, "%s is not set in the config file",
|
|
CFG_INSTANCEUUID);
|
|
return DC_ERR_CONFIG;
|
|
}
|
|
|
|
ret = uuid_parse((char *)cfgval, project_uuid);
|
|
if (ret)
|
|
{
|
|
DC_log(LOG_ERR, "Invalid project UUID");
|
|
free(cfgval);
|
|
return DC_ERR_CONFIG;
|
|
}
|
|
free(cfgval);
|
|
|
|
/* Enforce a canonical string representation of the UUID */
|
|
uuid_unparse_lower(project_uuid, project_uuid_str);
|
|
|
|
return DC_OK;
|
|
}
|
|
|
|
int DC_getMaxMessageSize(void)
|
|
{
|
|
return MAX_MESSAGE_SIZE;
|
|
}
|
|
|
|
int DC_getMaxSubresults(void)
|
|
{
|
|
return MAX_SUBRESULTS;
|
|
}
|
|
|
|
unsigned DC_getGridCapabilities(void)
|
|
{
|
|
return DC_GC_STDOUT | DC_GC_STDERR;
|
|
}
|
|
|
|
void DC_setMasterCb(DC_ResultCallback resultcb, DC_SubresultCallback subresultcb,
|
|
DC_MessageCallback msgcb)
|
|
{
|
|
_dc_resultcb = resultcb;
|
|
_dc_subresultcb = subresultcb;
|
|
_dc_messagecb = msgcb;
|
|
}
|