Compartilhar via


Server Support

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

The OBEX server is an extensible OS service that facilitates information exchange using Bluetooth or the IrOBEX 1.2 protocol. It acts as a protocol translator and forwards packets to the appropriate transport layer.

The server, itself, is implemented as Obexsrvr.dll, a service/device driver capable of running in the context of Device.exe or Services.exe. It supports two types of networking media: Bluetooth and IrDA. Each can be individually disabled. Network transport extensions are not supported.

Packet interpretation and request servicing is deferred to OBEX extensions, supplied by original equipment manufacturers (OEMs) and independent software vendors (ISVs).

Note

The OBEX server does not support command extensions. Received packets must fall under Connect, Disconnect, Put, Get, Abort, or Setpath, which are defined in the IrOBEX 1.2 Specification.

You cannot open a COM port that is opened by Obex because Obex has exclusive control of the port. The following sample code shows how to programmatically disable Obex so that you can open the port.

#include <windows.h>
#include <service.h>
HRESULT OBEXIOCTL(DWORD dwIOCTL)
{
    HANDLE hService;
    BOOL fRet;
    hService = CreateFile(L"OBX0:",GENERIC_READ|GENERIC_WRITE,0,
                          NULL,OPEN_EXISTING,0,NULL);
    if (INVALID_HANDLE_VALUE == hService)
        return FALSE;
    fRet = DeviceIoControl(hService,dwIOCTL,0,0,0,0,NULL,0);
    CloseHandle(hService);
    return (0 == fRet)?E_FAIL:S_OK;
}
DWORD OBEXQuery() 
{
    HANDLE hService;
    BOOL fRet;
    DWORD dwStatus;
    hService = CreateFile(L"OBX0:",GENERIC_READ|GENERIC_WRITE,0,
                          NULL,OPEN_EXISTING,0,NULL);
    if (INVALID_HANDLE_VALUE == hService)
        return FALSE;
    fRet = DeviceIoControl(hService,IOCTL_SERVICE_STATUS,0,0,&dwStatus,sizeof(DWORD),0, 0);
    CloseHandle(hService);
    if(0 == fRet) {
        return 0xFFFFFFFF;
    } else {
        return dwStatus;
    }
     
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd )
{
  HRESULT hr = S_OK;
  // Query the OBEX state. Based on this state, the server is toggled 
  //   off or on, and the server status is printed.
  switch(OBEXQuery()) {
       // If the server is off, turn it back on.
       case SERVICE_STATE_OFF:
            OutputDebugString(L"Server is off -- starting\n");
            hr = OBEXIOCTL(IOCTL_SERVICE_START);
            break;
       // If the server is on, turn it off.
       case SERVICE_STATE_ON:
            OutputDebugString(L"Server is on -- stopping\n");
            hr = OBEXIOCTL(IOCTL_SERVICE_STOP); 
            break;
       // Print Obex server status.
       case SERVICE_STATE_STARTING_UP:
            OutputDebugString(L"Server is starting up\n");
            break;
       case SERVICE_STATE_SHUTTING_DOWN:
            OutputDebugString(L"Server is shutting down\n");
            break;
       case SERVICE_STATE_UNLOADING:
            OutputDebugString(L"Server is unloading\n");
            break;
       case SERVICE_STATE_UNINITIALIZED:
            OutputDebugString(L"Server is uninitialized\n");
            break;
       default:
            OutputDebugString(L"Server state is unknown at this time\n");
            break;
  };
   if(FAILED(hr)) {
     OutputDebugString(L"Setting device IOCTL failed\n");
  }
  return 0;
}

The following topics contain more information about OBEX server support:

OBEX Server Architecture

Custom Service Extensions

See Also

Concepts

Client Support

Other Resources

OBEX Application Development