Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

237 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. channel.cpp
  5. Abstract:
  6. This module implements the foundation channel classes.
  7. Author:
  8. Brian Guarraci (briangu), 2001
  9. Revision History:
  10. --*/
  11. #include <emsapip.h>
  12. #include <emsapi.h>
  13. #include <ntddsac.h>
  14. EMSChannel::EMSChannel()
  15. /*++
  16. Routine Description:
  17. Constructor
  18. Arguments:
  19. None
  20. Return Value:
  21. N/A
  22. --*/
  23. {
  24. //
  25. // We do not have a handle yet,
  26. // so prevent ourselves from calling Close()
  27. //
  28. myHaveValidHandle = FALSE;
  29. }
  30. EMSChannel::~EMSChannel()
  31. /*++
  32. Routine Description:
  33. Desctructor
  34. Arguments:
  35. N/A
  36. Return Value:
  37. N/A
  38. --*/
  39. {
  40. //
  41. // If we have a valid handle,
  42. // then close the channel
  43. //
  44. if (HaveValidHandle()) {
  45. Close();
  46. }
  47. }
  48. EMSChannel*
  49. EMSChannel::Construct(
  50. IN SAC_CHANNEL_OPEN_ATTRIBUTES ChannelAttributes
  51. )
  52. /*++
  53. Routine Description:
  54. Create a new channel object
  55. Arguments:
  56. ChannelAttributes - the attributes of the channel to create
  57. Return Value:
  58. Status
  59. TRUE --> pHandle is valid
  60. --*/
  61. {
  62. EMSChannel *Channel;
  63. //
  64. // Create an uninitialized channel object
  65. //
  66. Channel = new EMSChannel();
  67. //
  68. // Attempt to open the specified channel
  69. //
  70. Channel->myHaveValidHandle = Channel->Open(ChannelAttributes);
  71. //
  72. // If we failed, then delete our channel object
  73. //
  74. if (!Channel->HaveValidHandle()) {
  75. delete Channel;
  76. //
  77. // return a NULL channel object
  78. //
  79. Channel = NULL;
  80. }
  81. return Channel;
  82. }
  83. BOOL
  84. EMSChannel::Open(
  85. IN SAC_CHANNEL_OPEN_ATTRIBUTES ChannelAttributes
  86. )
  87. /*++
  88. Routine Description:
  89. Open a SAC channel of the specified name
  90. Arguments:
  91. EMSChannelName - The name of the newly created channel
  92. ChannelAttributes - the attributes of the channel to create
  93. Return Value:
  94. Status
  95. TRUE --> pHandle is valid
  96. --*/
  97. {
  98. ASSERT(! HaveValidHandle());
  99. //
  100. // Attempt to open the channel
  101. //
  102. return SacChannelOpen(
  103. &myEMSChannelHandle,
  104. &ChannelAttributes
  105. );
  106. }
  107. BOOL
  108. EMSChannel::Close(
  109. VOID
  110. )
  111. /*++
  112. Routine Description:
  113. Close the specified SAC channel
  114. NOTE: the channel pointer is made NULL under all conditions
  115. Arguments:
  116. None
  117. Return Value:
  118. Status
  119. TRUE --> the channel was closed or we didn't need to close it
  120. --*/
  121. {
  122. ASSERT(HaveValidHandle());
  123. //
  124. // attempt to close the channel
  125. //
  126. return SacChannelClose(
  127. &myEMSChannelHandle
  128. );
  129. }
  130. BOOL
  131. EMSChannel::HasNewData(
  132. OUT PBOOL InputWaiting
  133. )
  134. /*++
  135. Routine Description:
  136. This routine checks to see if there is any waiting input for
  137. the channel specified by the handle
  138. Arguments:
  139. InputWaiting - the input buffer status
  140. Return Value:
  141. Status
  142. TRUE --> the buffer was sent
  143. --*/
  144. {
  145. ASSERT(HaveValidHandle());
  146. return SacChannelHasNewData(
  147. GetEMSChannelHandle(),
  148. InputWaiting
  149. );
  150. }