int main(int argc, const char* argv[]) { InitModuleObjects(); if ((argc >= 2) && ((stricmp(argv[1], "/version") == 0) || (stricmp(argv[1], "-v") == 0) || (stricmp(argv[1], "--version") == 0))) { printVersion(); return 0; } Owned<IFile> inifile = createIFile("dfuplus.ini"); if(argc < 2 && !(inifile->exists() && inifile->size() > 0)) { handleSyntax(); return 0; } if ((argc >= 2) && ((argv[1][0]=='/' || argv[1][0]=='-') && (argv[1][1]=='?' || argv[1][1]=='h'))) { handleSyntax(); return 0; } //queryLogMsgManager()->changeMonitorFilterOwn(queryStderrLogMsgHandler(), getPassNoneLogMsgFilter()); Owned<IProperties> globals = createProperties("dfuplus.ini", true); if(!build_globals(argc, argv, globals)) { fprintf(stderr, "ERROR: Invalid command syntax.\n"); releaseAtoms(); return DFUERR_InvalidCommandSyntax; } const char* action = globals->queryProp("action"); if(!action || !*action) { handleSyntax(); fprintf(stderr, "\nERROR: please specify one action"); releaseAtoms(); return DFUERR_TooFewArguments; } const char* server = globals->queryProp("server"); if (!server || !*server) { if (stricmp(action,"dafilesrv")==0) globals->setProp("server","127.0.0.1"); // dummy else { fprintf(stderr, "ERROR: Esp server url not specified.\n"); releaseAtoms(); return DFUERR_TooFewArguments; } } try { Owned<CDfuPlusHelper> helper = new CDfuPlusHelper(LINK(globals.get())); helper->doit(); } catch(IException* e) { StringBuffer errmsg; e->errorMessage(errmsg); fprintf(stderr, "%s\n", errmsg.str()); } releaseAtoms(); return 0; }
bool QueryHelper::doSubmitWorkUnit(FILE * fp, const char * wuid, const char* cluster) { Owned<IClientWUSubmitRequest> req = wuclient->createWUSubmitRequest(); req->setWuid(wuid); req->setCluster(cluster); req->setNotifyCluster(true); if(globals->hasProp("snapshot")) req->setSnapshot(globals->queryProp("snapshot")); Owned<IClientWUSubmitResponse> resp = wuclient->WUSubmit(req); if(!resp) { printf("error submitting workunit %s\n", wuid); return false; } else { const IMultiException* excep = &resp->getExceptions(); if(excep != NULL && excep->ordinality() > 0) { StringBuffer msg; excep->errorMessage(msg); printf("%s\n", msg.str()); return false; } printf("Workunit %s submitted\n", wuid); } // Wait for the results (or not) bool infinite = true; int timeout = -1; if(globals->hasProp("timeout")) { infinite = false; timeout = globals->getPropInt("timeout", 0)*1000; } bool compileOnly = globals->getPropInt("compileOnly", 0)!=0; bool returnOnWaitState = globals->getPropInt("returnOnWait", 0)!=0; if(timeout > 0 || infinite) { if (compileOnly) { Owned<IClientWUWaitRequest> req = wuclient->createWUWaitCompiledRequest(); req->setWuid(wuid); req->setWait(timeout); req->setReturnOnWait(returnOnWaitState); Owned<IClientWUWaitResponse> resp = wuclient->WUWaitCompiled(req); WUState s = (WUState)resp->getStateID(); return s == WUStateCompiled; } else { WUState s; int initial_wait = 30; int polling_period = 30; int waited = 0; int actual_wait = -1; while(1) { if(actual_wait != 0) { // Initially, wait initial_wait actual_wait = infinite?initial_wait*1000: std::min(timeout, initial_wait*1000); } Owned<IClientWUWaitRequest> req = wuclient->createWUWaitCompleteRequest(); req->setWuid(wuid); req->setWait(actual_wait); Owned<IClientWUWaitResponse> resp = wuclient->WUWaitComplete(req); const IMultiException* excep = &resp->getExceptions(); if(excep != NULL && excep->ordinality() > 0) { StringBuffer msg; excep->errorMessage(msg); printf("%s\n", msg.str()); return false; } s = (WUState)resp->getStateID(); if (s != WUStateUnknown) break; if(actual_wait != 0) { waited += actual_wait; actual_wait = 0; if (!infinite && (waited >= timeout)) break; } else { if (!infinite && (waited >= timeout)) break; int time_to_wait = infinite?polling_period*1000: std::min(timeout - waited, polling_period*1000); sleep(time_to_wait/1000); waited += time_to_wait; } } if (s != WUStateUnknown) { globals->setProp("wuid", wuid); if(format) LINK(format); Owned<IEclPlusHelper> viewer = new ViewHelper(LINK(globals), format); viewer->doit(fp); } return ((s == WUStateCompleted) || (returnOnWaitState && (s == WUStateWait))); } } else { StringBuffer s; s.append("Submitted WUID ").append(wuid); fprintf(fp, "%s", s.str()); return true; } }