namespace HDK_Sample {
class BackgroundTask {
public:
FILE *
open(
const char *cmd,
char *text=0,
int length=0)
{
FILE *fp;
{
{
fp = NULL;
}
else
fflush(fp);
}
return fp;
}
{
{
}
}
{
}
};
static void
pollTasks()
{
int i;
#if defined(DEMO_DEBUG)
fprintf(stderr,
"Poll: %d\n", theTasks.entries());
#endif
for (i = 0; i < theTasks.entries(); ++i)
{
if (theTasks(i)->isComplete())
{
#if defined(DEMO_DEBUG)
if (theTasks(i)->myPipe)
fprintf(stderr,
"Delete [%d] %s\n",
theTasks(i)->myPipe->getPid(),
(const char *)theTasks(i)->myCommand);
#endif
delete theTasks(i);
theTasks(i) = 0;
}
}
theTasks.collapse();
}
static void
listTasks(std::ostream &os)
{
int i;
os << theTasks.entries() << " background tasks\n";
for (i = 0; i < theTasks.entries(); i++)
{
if (theTasks(i)->myPipe)
{
os << i
<< " pid[" << theTasks(i)->myPipe->getPid()
<< "] " << theTasks(i)->myCommand
<< "\n";
}
}
}
public:
{ return "BackgroundTimer"; }
{
pollTasks();
if (!theTasks.entries())
return theTasks.entries() > 0;
}
{
#if defined(DEMO_DEBUG)
#endif
if (theTimer)
{
delete theTimer;
theTimer = NULL;
}
}
{
if (!theTimer)
{
#if defined(DEMO_DEBUG)
fprintf(stderr,
"Start polling\n");
#endif
{
delete theTimer;
theTimer = NULL;
}
}
}
private:
};
BackgroundTimer *BackgroundTimer::theTimer = NULL;
static void
{
else if (args.
argc() != 2)
{
args.
err() <<
"Usage: " <<
args(0) <<
" [-l] 'command'\n";
args.
err() <<
"Runs a command in the background\n";
args.
err() <<
"The -l option lists all current commands\n";
}
else
{
BackgroundTask *task;
task = new BackgroundTask();
if (task->open(args(1)))
{
theTasks.append(task);
}
else
{
args.
err() <<
"Error running: " <<
args(1) <<
"\n";
}
}
}
}
void
{
cman->
installCommand(
"hdk_background",
"l", HDK_Sample::hdk_background);
}