debugservices.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #include "platform.h"
  15. #include "debugservices.hpp"
  16. #define DEBUGSERVICES_VERSION "DEBUGSERVICES 1.0.1"
  17. const char * EclDefinition =
  18. "export DebugServices := SERVICE\n"
  19. " Sleep(integer millis) : c,pure,entrypoint='dsSleep',initFunction='dsInitDebugServices'; \n"
  20. " varstring GetBuildInfo() : c,pure,entrypoint='dsGetBuildInfo',initFunction='dsInitDebugServices';\n"
  21. "END;";
  22. static const char * compatibleVersions[] = {
  23. "DEBUGSERVICES 1.0 [7294888b4271178e0cfda307826d4823]",
  24. "DEBUGSERVICES 1.0.1",
  25. NULL };
  26. DEBUGSERVICES_API bool getECLPluginDefinition(ECLPluginDefinitionBlock *pb)
  27. {
  28. if (pb->size != sizeof(ECLPluginDefinitionBlock))
  29. return false;
  30. pb->magicVersion = PLUGIN_VERSION;
  31. pb->version = DEBUGSERVICES_VERSION;
  32. pb->moduleName = "lib_debugservices";
  33. pb->ECL = EclDefinition;
  34. pb->flags = PLUGIN_IMPLICIT_MODULE;
  35. pb->description = "DEBUGSERVICES library";
  36. return true;
  37. }
  38. DEBUGSERVICES_API char * DEBUGSERVICES_CALL dsGetBuildInfo(void)
  39. {
  40. return strdup(DEBUGSERVICES_VERSION);
  41. }
  42. //-------------------------------------------------------------------------------------------------------------------------------------------
  43. DEBUGSERVICES_API void DEBUGSERVICES_CALL dsSleep(unsigned milli)
  44. {
  45. #ifdef _WIN32
  46. Sleep(milli);
  47. #else
  48. timespec sleepTime;
  49. if (milli>=1000)
  50. {
  51. sleepTime.tv_sec = milli/1000;
  52. milli %= 1000;
  53. }
  54. else
  55. sleepTime.tv_sec = 0;
  56. sleepTime.tv_nsec = milli * 1000000;
  57. nanosleep(&sleepTime, NULL);
  58. #endif
  59. }