OpcomChannel.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // OpcomChannel.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/OpcomChannel.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Logging
  8. // Module: OpcomChannel
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/OpcomChannel.h"
  16. #include "Poco/Message.h"
  17. #include <starlet.h>
  18. #include <opcdef.h>
  19. #include <descrip.h>
  20. namespace Poco {
  21. const std::string OpcomChannel::PROP_TARGET = "target";
  22. OpcomChannel::OpcomChannel(): _target(OPC$M_NM_CENTRL)
  23. {
  24. }
  25. OpcomChannel::OpcomChannel(int target): _target(target)
  26. {
  27. }
  28. OpcomChannel::~OpcomChannel()
  29. {
  30. }
  31. void OpcomChannel::log(const Message& msg)
  32. {
  33. const std::string& text = msg.getText();
  34. // set up OPC buffer
  35. struct _opcdef buffer;
  36. buffer.opc$b_ms_type = OPC$_RQ_RQST;
  37. buffer.opc$b_ms_target = _target;
  38. buffer.opc$l_ms_rqstid = 0;
  39. int len = text.size();
  40. // restrict message text to 128 chars
  41. if (len > 128) len = 128;
  42. // copy message text into buffer
  43. memcpy(&buffer.opc$l_ms_text, text.data(), len);
  44. // sys$sndopr only accepts 32-bit pointers
  45. #pragma pointer_size save
  46. #pragma pointer_size 32
  47. // set up the descriptor
  48. struct dsc$descriptor bufferDsc;
  49. bufferDsc.dsc$w_length = len + 8;
  50. bufferDsc.dsc$a_pointer = (char*) &buffer;
  51. // call the system service
  52. sys$sndopr(&bufferDsc, 0);
  53. #pragma pointer_size restore
  54. }
  55. void OpcomChannel::setProperty(const std::string& name, const std::string& value)
  56. {
  57. if (name == PROP_TARGET)
  58. {
  59. if (value == "CARDS")
  60. _target = OPC$M_NM_CARDS;
  61. else if (value == "CENTRL")
  62. _target = OPC$M_NM_CENTRL;
  63. else if (value == "CLUSTER")
  64. _target = OPC$M_NM_CLUSTER;
  65. else if (value == "DEVICE")
  66. _target = OPC$M_NM_DEVICE;
  67. else if (value == "DISKS")
  68. _target = OPC$M_NM_DISKS;
  69. else if (value == "NTWORK")
  70. _target = OPC$M_NM_NTWORK;
  71. else if (value == "TAPES")
  72. _target = OPC$M_NM_TAPES;
  73. else if (value == "PRINT")
  74. _target = OPC$M_NM_PRINT;
  75. else if (value == "SECURITY")
  76. _target = OPC$M_NM_SECURITY;
  77. else if (value == "OPER1")
  78. _target = OPC$M_NM_OPER1;
  79. else if (value == "OPER2")
  80. _target = OPC$M_NM_OPER2;
  81. else if (value == "OPER3")
  82. _target = OPC$M_NM_OPER3;
  83. else if (value == "OPER4")
  84. _target = OPC$M_NM_OPER4;
  85. else if (value == "OPER5")
  86. _target = OPC$M_NM_OPER5;
  87. else if (value == "OPER6")
  88. _target = OPC$M_NM_OPER6;
  89. else if (value == "OPER7")
  90. _target = OPC$M_NM_OPER7;
  91. else if (value == "OPER8")
  92. _target = OPC$M_NM_OPER8;
  93. else if (value == "OPER9")
  94. _target = OPC$M_NM_OPER9;
  95. else if (value == "OPER10")
  96. _target = OPC$M_NM_OPER10;
  97. else if (value == "OPER11")
  98. _target = OPC$M_NM_OPER11;
  99. else if (value == "OPER12")
  100. _target = OPC$M_NM_OPER12;
  101. }
  102. else
  103. {
  104. Channel::setProperty(name, value);
  105. }
  106. }
  107. std::string OpcomChannel::getProperty(const std::string& name) const
  108. {
  109. if (name == PROP_TARGET)
  110. {
  111. if (_target == OPC$M_NM_CARDS)
  112. return "CARDS";
  113. else if (_target == OPC$M_NM_CENTRL)
  114. return "CENTRL";
  115. else if (_target == OPC$M_NM_CLUSTER)
  116. return "CLUSTER";
  117. else if (_target == OPC$M_NM_DEVICE)
  118. return "DEVICE";
  119. else if (_target == OPC$M_NM_DISKS)
  120. return "DISKS";
  121. else if (_target == OPC$M_NM_NTWORK)
  122. return "NTWORK";
  123. else if (_target == OPC$M_NM_TAPES)
  124. return "TAPES";
  125. else if (_target == OPC$M_NM_PRINT)
  126. return "PRINT";
  127. else if (_target == OPC$M_NM_SECURITY)
  128. return "SECURITY";
  129. else if (_target == OPC$M_NM_OPER1)
  130. return "OPER1";
  131. else if (_target == OPC$M_NM_OPER2)
  132. return "OPER2";
  133. else if (_target == OPC$M_NM_OPER3)
  134. return "OPER3";
  135. else if (_target == OPC$M_NM_OPER4)
  136. return "OPER4";
  137. else if (_target == OPC$M_NM_OPER5)
  138. return "OPER5";
  139. else if (_target == OPC$M_NM_OPER6)
  140. return "OPER6";
  141. else if (_target == OPC$M_NM_OPER7)
  142. return "OPER7";
  143. else if (_target == OPC$M_NM_OPER8)
  144. return "OPER8";
  145. else if (_target == OPC$M_NM_OPER9)
  146. return "OPER9";
  147. else if (_target == OPC$M_NM_OPER10)
  148. return "OPER10";
  149. else if (_target == OPC$M_NM_OPER11)
  150. return "OPER11";
  151. else if (_target == OPC$M_NM_OPER12)
  152. return "OPER12";
  153. }
  154. return Channel::getProperty(name);
  155. }
  156. } // namespace Poco