ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

wlansvc.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:        See COPYING in the top level directory
00003  * PROJECT:          ReactOS kernel
00004  * FILE:             services/wlansvc/wlansvc.c
00005  * PURPOSE:          WLAN Service
00006  * PROGRAMMER:       Christoph von Wittich
00007  */
00008 
00009 /* INCLUDES *****************************************************************/
00010 
00011 #define WIN32_NO_STATUS
00012 #include <windows.h>
00013 #include "wlansvc_s.h"
00014 
00015 //#define NDEBUG
00016 #include <debug.h>
00017 
00018 /* GLOBALS ******************************************************************/
00019 
00020 #define SERVICE_NAME L"WLAN Service"
00021 
00022 SERVICE_STATUS_HANDLE ServiceStatusHandle;
00023 SERVICE_STATUS SvcStatus;
00024 static WCHAR ServiceName[] = L"WlanSvc";
00025 
00026 /* FUNCTIONS *****************************************************************/
00027 static DWORD WINAPI RpcThreadRoutine(LPVOID lpParameter)
00028 {
00029     RPC_STATUS Status;
00030 
00031     Status = RpcServerUseProtseqEpW(L"ncalrpc", 20, L"wlansvc", NULL);
00032     if (Status != RPC_S_OK)
00033     {
00034         DPRINT("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
00035         return 0;
00036     }
00037 
00038     Status = RpcServerRegisterIf(wlansvc_interface_v1_0_s_ifspec, NULL, NULL);
00039     if (Status != RPC_S_OK)
00040     {
00041         DPRINT("RpcServerRegisterIf() failed (Status %lx)\n", Status);
00042         return 0;
00043     }
00044 
00045     Status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, 0);
00046     if (Status != RPC_S_OK)
00047     {
00048         DPRINT("RpcServerListen() failed (Status %lx)\n", Status);
00049     }
00050 
00051     DPRINT("RpcServerListen finished\n");
00052     return 0;
00053 }
00054 
00055 static void UpdateServiceStatus(HANDLE hServiceStatus, DWORD NewStatus, DWORD Increment)
00056 {
00057     if (Increment > 0)
00058         SvcStatus.dwCheckPoint += Increment;
00059     else
00060         SvcStatus.dwCheckPoint = 0;
00061 
00062     SvcStatus.dwCurrentState = NewStatus;
00063     SetServiceStatus(hServiceStatus, &SvcStatus);
00064 }
00065 
00066 static DWORD WINAPI
00067 ServiceControlHandler(DWORD dwControl,
00068                       DWORD dwEventType,
00069                       LPVOID lpEventData,
00070                       LPVOID lpContext)
00071 {
00072     switch (dwControl)
00073     {
00074         case SERVICE_CONTROL_SHUTDOWN:
00075         case SERVICE_CONTROL_STOP:
00076             UpdateServiceStatus(ServiceStatusHandle, SERVICE_STOP_PENDING, 1);
00077             RpcMgmtStopServerListening(NULL);
00078             UpdateServiceStatus(ServiceStatusHandle, SERVICE_STOPPED, 0);
00079             break;
00080         case SERVICE_CONTROL_INTERROGATE:
00081             return NO_ERROR;
00082         default:
00083             return ERROR_CALL_NOT_IMPLEMENTED;
00084     }
00085     return NO_ERROR;
00086 }
00087 
00088 static VOID CALLBACK
00089 ServiceMain(DWORD argc, LPWSTR *argv)
00090 {
00091     HANDLE hThread;
00092 
00093     UNREFERENCED_PARAMETER(argc);
00094     UNREFERENCED_PARAMETER(argv);
00095 
00096     DPRINT("ServiceMain() called\n");
00097 
00098     SvcStatus.dwServiceType             = SERVICE_WIN32_OWN_PROCESS;
00099     SvcStatus.dwCurrentState            = SERVICE_START_PENDING;
00100     SvcStatus.dwControlsAccepted        = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
00101     SvcStatus.dwCheckPoint              = 0;
00102     SvcStatus.dwWin32ExitCode           = NO_ERROR;
00103     SvcStatus.dwServiceSpecificExitCode = 0;
00104     SvcStatus.dwWaitHint                = 4000;
00105 
00106     ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
00107                                                         ServiceControlHandler,
00108                                                         NULL);
00109 
00110     UpdateServiceStatus(ServiceStatusHandle, SERVICE_RUNNING, 0);
00111 
00112     hThread = CreateThread(NULL,
00113                            0,
00114                            (LPTHREAD_START_ROUTINE)
00115                            RpcThreadRoutine,
00116                            NULL,
00117                            0,
00118                            NULL);
00119 
00120     if (!hThread)
00121     {
00122         DPRINT("Can't create RpcThread\n");
00123         UpdateServiceStatus(ServiceStatusHandle, SERVICE_STOPPED, 0);
00124     }
00125     else
00126     {
00127         CloseHandle(hThread);
00128     }
00129 
00130     DPRINT("ServiceMain() done\n");
00131 }
00132 
00133 int
00134 wmain(int argc, WCHAR *argv[])
00135 {
00136     SERVICE_TABLE_ENTRYW ServiceTable[2] =
00137     {
00138         {ServiceName, ServiceMain},
00139         {NULL, NULL}
00140     };
00141 
00142     UNREFERENCED_PARAMETER(argc);
00143     UNREFERENCED_PARAMETER(argv);
00144 
00145     DPRINT("wlansvc: main() started\n");
00146 
00147     StartServiceCtrlDispatcherW(ServiceTable);
00148 
00149     DPRINT("wlansvc: main() done\n");
00150 
00151     ExitThread(0);
00152 
00153     return 0;
00154 }
00155 
00156 /* EOF */

Generated on Wed May 23 2012 04:16:06 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.