2007-01-25 09:54:23 +00:00
|
|
|
/*
|
|
|
|
* local/local_client.c
|
|
|
|
*
|
|
|
|
* DC-API functions of client side
|
|
|
|
*
|
|
|
|
* (c) Gabor Vida 2005-2006, Daniel Drotos, 2007
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
/* $Date$ */
|
|
|
|
/* $Revision$ */
|
|
|
|
|
2006-02-16 15:30:10 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2006-04-11 14:09:55 +00:00
|
|
|
#include <string.h>
|
2007-02-04 16:52:46 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2006-02-16 15:30:10 +00:00
|
|
|
|
|
|
|
#include <dc_client.h>
|
2007-01-25 09:11:55 +00:00
|
|
|
|
|
|
|
#include "local_common.h"
|
2006-02-16 15:30:10 +00:00
|
|
|
|
2007-02-04 16:52:46 +00:00
|
|
|
|
|
|
|
static int _DC_checkpoint_file_requested= 0;
|
|
|
|
static int _DC_checkpoint_made= 0;
|
|
|
|
|
|
|
|
static char *
|
|
|
|
_DC_cfg(enum _DC_e_param what)
|
|
|
|
{
|
|
|
|
if (what >= cfg_nuof)
|
|
|
|
return(NULL);
|
|
|
|
if (_DC_params[what].lvalue)
|
|
|
|
return(_DC_params[what].lvalue);
|
|
|
|
|
|
|
|
_DC_params[what].lvalue= DC_getCfgStr(_DC_params[what].name);
|
|
|
|
if (_DC_params[what].lvalue)
|
|
|
|
return(_DC_params[what].lvalue);
|
|
|
|
return(_DC_params[what].def);
|
|
|
|
}
|
|
|
|
|
2006-04-11 14:09:55 +00:00
|
|
|
/********************************************************************
|
|
|
|
* Common API functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
int DC_getMaxMessageSize(void)
|
|
|
|
{
|
|
|
|
return MAX_MESSAGE_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DC_getMaxSubresults(void)
|
|
|
|
{
|
|
|
|
return MAX_SUBRESULTS;
|
|
|
|
}
|
|
|
|
|
2006-05-19 13:39:25 +00:00
|
|
|
unsigned DC_getGridCapabilities(void)
|
2006-04-11 14:09:55 +00:00
|
|
|
{
|
|
|
|
return (DC_GridCapabilities)(DC_GC_STDERR | DC_GC_STDOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* Client API functions
|
|
|
|
*/
|
2006-02-16 15:30:10 +00:00
|
|
|
|
2006-05-19 13:39:25 +00:00
|
|
|
int DC_initClient(void)
|
2006-02-16 15:30:10 +00:00
|
|
|
{
|
2007-01-25 12:37:10 +00:00
|
|
|
_DC_init_common();
|
2006-04-11 14:09:55 +00:00
|
|
|
return 0;
|
2006-02-16 15:30:10 +00:00
|
|
|
}
|
|
|
|
|
2006-04-08 11:50:14 +00:00
|
|
|
char *DC_resolveFileName(DC_FileType type, const char *logicalFileName)
|
2006-02-16 15:30:10 +00:00
|
|
|
{
|
2007-02-04 16:52:46 +00:00
|
|
|
/* init_log calls this fn, so it is not possible to call DC_log
|
|
|
|
from here */
|
|
|
|
/*DC_log(LOG_DEBUG, "DC_resolveFileName(%d,%s)",
|
|
|
|
type, logicalFileName);*/
|
|
|
|
char *cn= _DC_cfg(cfg_checkpoint_file);
|
|
|
|
if (!strcmp(logicalFileName, DC_CHECKPOINT_FILE))
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case DC_FILE_IN:
|
|
|
|
{
|
|
|
|
/* - param of last DC_checkpointMade()
|
|
|
|
- filename created by previous run
|
|
|
|
- NULL otherwise */
|
|
|
|
if (_DC_checkpoint_made)
|
|
|
|
{
|
|
|
|
char *fn= (char*)malloc(strlen(cn)+100);
|
|
|
|
sprintf(fn, "%s_finished.txt", cn);
|
|
|
|
return(fn);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char *fn= (char*)malloc(strlen(cn)+100);
|
|
|
|
sprintf(fn, "%s_finished.txt", cn);
|
|
|
|
if ((f= fopen(fn, "r")) != NULL)
|
|
|
|
{
|
|
|
|
fclose(f);
|
|
|
|
return(fn);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(fn);
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DC_FILE_OUT:
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
/* new non-existant name */
|
|
|
|
if (_DC_checkpoint_file_requested)
|
|
|
|
{
|
|
|
|
DC_log(LOG_ERR, "Checkpoint file creation "
|
|
|
|
"can not be restarted "
|
|
|
|
"(DC_resolveFileName("
|
|
|
|
DC_CHECKPOINT_FILE
|
|
|
|
") called twice without calling of "
|
|
|
|
"DC_checkpointMade())");
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
_DC_checkpoint_file_requested= 1;
|
|
|
|
s= (char*)malloc(strlen(cn)+100);
|
|
|
|
sprintf(s, "%s_creating.txt", cn);
|
|
|
|
return(s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(strdup((char*)logicalFileName));
|
|
|
|
/*
|
2006-04-11 14:09:55 +00:00
|
|
|
if (!strcmp(logicalFileName, DC_CHECKPOINT_FILE))
|
|
|
|
{
|
2006-06-20 17:28:02 +00:00
|
|
|
return strdup(CKPT_LABEL);
|
2006-04-11 14:09:55 +00:00
|
|
|
}
|
2006-06-20 17:28:02 +00:00
|
|
|
return strdup(logicalFileName);
|
2007-02-04 16:52:46 +00:00
|
|
|
*/
|
2006-04-07 14:18:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int DC_sendResult(const char *logicalFileName, const char *path, DC_FileMode fileMode)
|
|
|
|
{
|
2006-04-11 14:09:55 +00:00
|
|
|
// not implemented yet!
|
2006-04-07 14:18:11 +00:00
|
|
|
|
2006-04-11 14:09:55 +00:00
|
|
|
return DC_ERR_NOTIMPL;
|
2006-02-16 15:30:10 +00:00
|
|
|
}
|
|
|
|
|
2006-04-07 14:18:11 +00:00
|
|
|
int DC_sendMessage(const char *message)
|
2006-02-16 15:30:10 +00:00
|
|
|
{
|
2006-04-11 14:09:55 +00:00
|
|
|
// not implemented yet!
|
2006-02-16 15:30:10 +00:00
|
|
|
|
2006-04-11 14:09:55 +00:00
|
|
|
return DC_ERR_NOTIMPL;
|
2006-02-16 15:30:10 +00:00
|
|
|
}
|
|
|
|
|
2006-05-19 13:39:25 +00:00
|
|
|
DC_ClientEvent *DC_checkClientEvent(void)
|
2006-04-07 14:18:11 +00:00
|
|
|
{
|
2006-04-11 14:09:55 +00:00
|
|
|
// not implemented yet!
|
2006-04-07 14:18:11 +00:00
|
|
|
|
2006-04-11 14:09:55 +00:00
|
|
|
return NULL;
|
2006-04-07 14:18:11 +00:00
|
|
|
}
|
|
|
|
|
2006-05-19 13:39:25 +00:00
|
|
|
void DC_destroyClientEvent(DC_ClientEvent *event)
|
2006-04-08 11:50:14 +00:00
|
|
|
{
|
2006-04-11 14:09:55 +00:00
|
|
|
// not implemented yet!
|
2006-04-08 11:50:14 +00:00
|
|
|
}
|
|
|
|
|
2006-04-07 14:18:11 +00:00
|
|
|
void DC_checkpointMade(const char *fileName)
|
2006-02-16 15:30:10 +00:00
|
|
|
{
|
2007-02-04 16:52:46 +00:00
|
|
|
DC_log(LOG_DEBUG, "DC_checkpointMade(%s)", fileName);
|
|
|
|
_DC_checkpoint_file_requested= 0;
|
|
|
|
if (fileName)
|
|
|
|
{
|
|
|
|
char *cn= _DC_cfg(cfg_checkpoint_file);
|
|
|
|
char *fn;
|
|
|
|
fn= (char*)malloc(strlen(cn)+100);
|
|
|
|
sprintf(fn, "%s_finished.txt", cn);
|
|
|
|
if (rename(fileName, fn) != 0)
|
|
|
|
{
|
|
|
|
DC_log(LOG_ERR, "Renaming %s to %s failed: %s",
|
|
|
|
fileName, fn, strerror(errno));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_DC_checkpoint_made++;
|
|
|
|
free(fn);
|
|
|
|
}
|
2006-02-16 15:30:10 +00:00
|
|
|
}
|
|
|
|
|
2006-04-07 14:18:11 +00:00
|
|
|
void DC_fractionDone(double fraction)
|
2006-02-16 15:30:10 +00:00
|
|
|
{
|
2006-04-11 14:09:55 +00:00
|
|
|
// Nothing to do with it.
|
2006-02-16 15:30:10 +00:00
|
|
|
}
|
|
|
|
|
2006-05-19 13:39:25 +00:00
|
|
|
void DC_finishClient(int exitcode)
|
2006-02-16 15:30:10 +00:00
|
|
|
{
|
2006-04-11 14:09:55 +00:00
|
|
|
// XXX Need to send a message to the master side of the DC_API!
|
|
|
|
|
|
|
|
exit(exitcode);
|
2006-02-16 15:30:10 +00:00
|
|
|
}
|
2007-01-25 09:54:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* End of local/local_client.c */
|
|
|
|
|
|
|
|
/* Local variables: */
|
|
|
|
/* c-file-style: "linux" */
|
|
|
|
/* End: */
|