thorport.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #ifndef __THORPORT__
  14. #define __THORPORT__
  15. #include "jarray.hpp"
  16. #include "jutil.hpp"
  17. #include "jsocket.hpp"
  18. #ifdef _WIN32
  19. #ifdef GRAPH_EXPORTS
  20. #define graph_decl __declspec(dllexport)
  21. #else
  22. #define graph_decl __declspec(dllimport)
  23. #endif
  24. #else
  25. #define graph_decl
  26. #endif
  27. enum ThorPortKind
  28. {
  29. TPORT_watchdog,
  30. TPORT_mp
  31. };
  32. graph_decl unsigned short getFixedPort(ThorPortKind category);
  33. graph_decl unsigned short getFixedPort(unsigned short base, ThorPortKind category);
  34. graph_decl unsigned short getExternalFixedPort(unsigned short masterbase, unsigned short machinebase, ThorPortKind category);
  35. graph_decl unsigned short allocPort(unsigned num=1);
  36. graph_decl void freePort(unsigned short,unsigned num=1);
  37. graph_decl void setMachinePortBase(unsigned short base);
  38. graph_decl void setMasterPortBase(unsigned short base);
  39. graph_decl unsigned short getMasterPortBase();
  40. graph_decl unsigned short getMachinePortBase();
  41. typedef UnsignedShortArray PortArray;
  42. class CPortGroup
  43. {
  44. public:
  45. unsigned short allocPort(unsigned n=1)
  46. {
  47. unsigned short p=::allocPort(n);
  48. while (n--)
  49. portsinuse.append(p+n);
  50. return p;
  51. }
  52. void freePort(unsigned short p,unsigned n=1)
  53. {
  54. unsigned i;
  55. for (i=0;i<n;i++)
  56. portsinuse.zap(p+i);
  57. ::freePort(p,n);
  58. }
  59. virtual ~CPortGroup()
  60. {
  61. ForEachItemIn(i,portsinuse) {
  62. freePort(portsinuse.item(i));
  63. }
  64. }
  65. protected:
  66. PortArray portsinuse;
  67. };
  68. #endif