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.

166 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. itsrv.c
  5. Abstract:
  6. This module builds a console test program that registers RPC
  7. interfaces for idle detection and runs as the idle detection server.
  8. The quality of the code for the test programs is as such.
  9. Author:
  10. Cenk Ergan (cenke)
  11. Environment:
  12. User Mode
  13. --*/
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <windows.h>
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include "idlrpc.h"
  21. #include "idlesrv.h"
  22. //
  23. // Note that the following code is test quality code.
  24. //
  25. HANDLE ItTstStopEvent = NULL;
  26. BOOL
  27. ItTstConsoleHandler(DWORD dwControl)
  28. {
  29. if (ItTstStopEvent) {
  30. SetEvent(ItTstStopEvent);
  31. }
  32. return TRUE;
  33. }
  34. VOID
  35. LogTaskStatus(
  36. LPCTSTR ptszTaskName,
  37. LPTSTR ptszTaskTarget,
  38. UINT uMsgID,
  39. DWORD dwExitCode
  40. )
  41. {
  42. return;
  43. }
  44. int
  45. __cdecl
  46. main(int argc, char* argv[])
  47. {
  48. DWORD ErrorCode;
  49. DWORD WaitResult;
  50. BOOLEAN StartedIdleDetectionServer;
  51. //
  52. // Initialize locals.
  53. //
  54. StartedIdleDetectionServer = FALSE;
  55. //
  56. // Create the event to be signaled when we should stop.
  57. //
  58. ItTstStopEvent = CreateEvent (NULL,
  59. TRUE,
  60. FALSE,
  61. NULL);
  62. if (ItTstStopEvent == NULL) {
  63. ErrorCode = GetLastError();
  64. goto cleanup;
  65. }
  66. //
  67. // Specify Control-C handler.
  68. //
  69. SetConsoleCtrlHandler(ItTstConsoleHandler, TRUE);
  70. //
  71. // Specify which protocol sequences to use. (just LPC)
  72. //
  73. ErrorCode = RpcServerUseProtseq(IT_RPC_PROTSEQ,
  74. 256,
  75. NULL);
  76. if (ErrorCode != RPC_S_OK) {
  77. goto cleanup;
  78. }
  79. //
  80. // Start the idle detection server.
  81. //
  82. ErrorCode = ItSrvInitialize();
  83. if (ErrorCode != ERROR_SUCCESS) {
  84. goto cleanup;
  85. }
  86. StartedIdleDetectionServer = TRUE;
  87. printf("Started idle detection server...\n");
  88. //
  89. // Wait for the exit event to be signaled.
  90. //
  91. WaitResult = WaitForSingleObject(ItTstStopEvent, INFINITE);
  92. if (WaitResult != WAIT_OBJECT_0) {
  93. ErrorCode = GetLastError();
  94. goto cleanup;
  95. }
  96. //
  97. // We are done.
  98. //
  99. ErrorCode = ERROR_SUCCESS;
  100. cleanup:
  101. if (StartedIdleDetectionServer) {
  102. ItSrvUninitialize();
  103. }
  104. if (ItTstStopEvent) {
  105. CloseHandle(ItTstStopEvent);
  106. }
  107. printf("Exiting idle detection server with error code: %d\n", ErrorCode);
  108. return ErrorCode;
  109. }
  110. /*********************************************************************/
  111. /* MIDL allocate and free */
  112. /*********************************************************************/
  113. void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
  114. {
  115. return(HeapAlloc(GetProcessHeap(),0,(len)));
  116. }
  117. void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
  118. {
  119. HeapFree(GetProcessHeap(),0,(ptr));
  120. }