36 namespace HDK_Sample {
62 if (fp && text &&
length > 0)
106 #if defined(DEMO_DEBUG)
107 fprintf(stderr,
"Poll: %d\n", theTasks.entries());
109 for (i = 0; i < theTasks.entries(); ++i)
111 if (theTasks(i)->isComplete())
113 #if defined(DEMO_DEBUG)
114 if (theTasks(i)->myPipe)
115 fprintf(stderr,
"Delete [%d] %s\n",
116 theTasks(i)->myPipe->getPid(),
117 (
const char *)theTasks(i)->myCommand);
128 listTasks(std::ostream &os)
131 os << theTasks.entries() <<
" background tasks\n";
132 for (i = 0; i < theTasks.entries(); i++)
134 if (theTasks(i)->myPipe)
137 <<
" pid[" << theTasks(i)->myPipe->getPid()
138 <<
"] " << theTasks(i)->myCommand
157 {
return "BackgroundTimer"; }
167 if (!theTasks.entries())
170 return theTasks.entries() > 0;
176 #if defined(DEMO_DEBUG)
177 fprintf(stderr,
"Stop polling\n");
194 #if defined(DEMO_DEBUG)
195 fprintf(stderr,
"Start polling\n");
211 BackgroundTimer *BackgroundTimer::theTimer = NULL;
218 listTasks(args.
out());
219 else if (args.
argc() != 2)
221 args.
err() <<
"Usage: " <<
args(0) <<
" [-l] 'command'\n";
222 args.
err() <<
"Runs a command in the background\n";
223 args.
err() <<
"The -l option lists all current commands\n";
227 BackgroundTask *task;
228 task =
new BackgroundTask();
229 if (task->open(args(1)))
231 theTasks.append(task);
236 args.
err() <<
"Error running: " <<
args(1) <<
"\n";
249 cman->
installCommand(
"hdk_background",
"l", HDK_Sample::hdk_background);
Event generator to poll for completed tasks.
FILE * open(const char *cmd, char *text=0, int length=0)
std::ostream & err(int show_line_number=1)
FILE * open(const char *cmd)
void uninstallGenerator()
bool isComplete(bool block=false)
GLuint GLsizei GLsizei * length
bool isComplete()
Test if the background process is complete.
void installCommand(const char *name, const char *options, CMD_Callback cb, bool is_safe=true)
Install a command into the command list.
int getPollTime() override
Poll time is in ms, so poll every 0.5 seconds.
void close()
Close the pipe, blocking until the pipe is complete.
void harden()
Take shallow copy and make it deep.
static void startPolling()
Start polling process.
int close(bool wait_for_child_to_terminate=false)
auto fprintf(std::FILE *f, const S &fmt, const T &...args) -> int
const char * getClassName() const override
BackgroundTask is the object which keeps track of the background process.
void CMDextendLibrary(CMD_Manager *cman)
**If you just want to fire and args
static void stopPolling()
Stop polling process.
int processEvents() override
This callback is used to process events.
~BackgroundTimer() override