dfu2.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include <platform.h>
  14. #include <stdio.h>
  15. #include <limits.h>
  16. #include "jexcept.hpp"
  17. #include "jptree.hpp"
  18. #include "jsocket.hpp"
  19. #include "jstring.hpp"
  20. #include "jmisc.hpp"
  21. #include "daclient.hpp"
  22. #include "dadfs.hpp"
  23. #include "dasds.hpp"
  24. #include "jio.hpp"
  25. #include "daft.hpp"
  26. #include "daftcfg.hpp"
  27. #include "fterror.hpp"
  28. #include "rmtfile.hpp"
  29. #include "daftprogress.hpp"
  30. #include "dfurun.hpp"
  31. #include "dfuwu.hpp"
  32. #include "jprop.hpp"
  33. #include "dfuerror.hpp"
  34. IProperties *iniFile;
  35. #define MAX_COPIES 4
  36. bool verbose = true;
  37. enum display_type {display_header, display_file, display_directory};
  38. //============================================================================
  39. void handleSyntax()
  40. {
  41. printf("Usage:\n");
  42. printf(" DFU2 SERVER DALISERVERS=<ip> <queue-name> { <queue-name> } -- starts DFU server\n\n");
  43. }
  44. void cmdServer(int argc, const char *argv[])
  45. {
  46. Owned<IDFUengine> engine = createDFUengine();
  47. if (argc<3)
  48. printf("No queue specified for server");
  49. else {
  50. unsigned i;
  51. for (i=2;i<argc;i++) {
  52. engine->startListener(argv[i]);
  53. }
  54. engine->joinListeners();
  55. }
  56. }
  57. bool actionOnAbort()
  58. {
  59. LOG(MCprogress, unknownJob, "Exiting");
  60. closeEnvironment();
  61. closedownClientProcess();
  62. releaseAtoms();
  63. return true;
  64. }
  65. int main(int argc, const char *argv[])
  66. {
  67. InitModuleObjects();
  68. StringBuffer daliServer;
  69. // look for overrides
  70. unsigned i;
  71. unsigned j=1;
  72. for (i=1;i<argc;i++) {
  73. if ((strlen(argv[i])>12)&&memicmp(argv[i],"DALISERVERS=",12)==0)
  74. daliServer.append(strlen(argv[i])-12,argv[i]+12);
  75. else
  76. argv[j++] = argv[i];
  77. }
  78. argc = j;
  79. if (argc < 2 || argv[1][0]=='/' && argv[1][1]=='?')
  80. {
  81. handleSyntax();
  82. return argc<2 ? DFUERR_InvalidCommandSyntax : 0;
  83. }
  84. int ret = 0;
  85. try {
  86. iniFile = createProperties("dfu2.ini",true);
  87. StringBuffer logFile;
  88. if (!iniFile->getProp("LOGFILE", logFile))
  89. logFile.append("DFU2.log");
  90. attachStandardFileLogMsgMonitor(logFile.str(), NULL, MSGFIELD_STANDARD, MSGAUD_all, MSGCLS_all, TopDetail, false);
  91. unsigned userDetail = iniFile->getPropInt("DETAIL", DefaultDetail);
  92. ILogMsgFilter * userOperator = getCategoryLogMsgFilter(MSGAUD_all, MSGCLS_disaster|MSGCLS_error|MSGCLS_warning, userDetail, true);
  93. ILogMsgFilter * errWarn = getCategoryLogMsgFilter(MSGAUD_operator|MSGAUD_user, MSGCLS_all, TopDetail, true);
  94. ILogMsgFilter * combinedFilter = getOrLogMsgFilterOwn(userOperator, errWarn);
  95. queryLogMsgManager()->changeMonitorFilterOwn(queryStderrLogMsgHandler(), combinedFilter);
  96. queryStderrLogMsgHandler()->setMessageFields(0);
  97. if (!daliServer.length()&&!iniFile->getProp("DALISERVERS", daliServer))
  98. throwError(DFUERR_NoDaliServerList);
  99. Owned<IGroup> serverGroup = createIGroup(daliServer.str(),DALI_SERVER_PORT);
  100. initClientProcess(serverGroup, 0, NULL, NULL, MP_WAIT_FOREVER, true); // so that
  101. DFUcmd cmd = decodeDFUcommand(argv[1]);
  102. addAbortHandler(actionOnAbort);
  103. try {
  104. switch(cmd) {
  105. case DFUcmd_server:
  106. cmdServer(argc, argv);
  107. break;
  108. case DFUcmd_none:
  109. break;
  110. default:
  111. // chain to DFUcmd for rest TBD
  112. printf("DFU2 %s not yet implemented.\n",argv[1]);
  113. }
  114. }
  115. catch(IException *e)
  116. {
  117. EXCLOG(e, "DFU Exception: ");
  118. ret = e->errorCode();
  119. e->Release();
  120. }
  121. catch (const char *s) {
  122. IERRLOG("DFU: %s",s);
  123. }
  124. }
  125. catch(IException *e){
  126. EXCLOG(e, "DFU Exception: ");
  127. ret = e->errorCode();
  128. if (e->errorCode() == DFUERR_InvalidCommandSyntax || e->errorCode() == DFUERR_TooFewArguments)
  129. handleSyntax();
  130. e->Release();
  131. }
  132. catch (const char *s) {
  133. IERRLOG("DFU: %s",s);
  134. }
  135. closeEnvironment();
  136. closedownClientProcess();
  137. releaseAtoms();
  138. return ret;
  139. }