Directly Accessing the OBEX Headers (Windows Embedded CE 6.0)

1/6/2010

During send and receive operations, some applications may need to access the OBEX headers sent by the server that are not directly available from the IStream interface. Windows Mobile provides a mechanism for retrieving headers for multiple-packet responses. OBEX clients can now access various custom headers in the OBEX stream. This enables OEMs to integrate their custom Basic Imaging Profile (BIP) over the Windows Embedded CE Bluetooth stack.

Ee494532.note(en-US,WinEmbedded.60).gifNote:
BIP is not supported by Windows Mobile. It provides the additional capabilities required by OBEX to support BIP. OEMs will need to implement their own BIP functionality.

To determine the OBEX headers that have been set by a server, call IUnknown::QueryInterface on the IStream object that was used for sending and receiving the raw data by passing the UUID, IID_IHeaderEnum in the iid parameter.

QueryInterface returns an IHeaderEnum:IUnknown object that can be used to enumerate the headers that the server returned.

Ee494532.note(en-US,WinEmbedded.60).gifNote:
The header values cannot be queried at any point during an IStream operation. When the application retrieves data from the OBEX server by using the IStream::Read method, the server also returns the set of OBEX headers. However, querying for IHeaderEnum at any point during the operation always returns the headers from the initial response packet. The IStream object does not store headers that the OBEX server sends after the first packet. If QueryInterface is called before the first operation, the call fails with an E_FAIL code. For sending data to an OBEX server by using the IStream::Write method, only the headers in the last packet that the server returns are available. Typically, when the client application calls the IStream::Commit method, the OBEX server sends a notification to the caller indicating that the last packet has been sent. After this notification is sent, the IStream object stores the headers for future retrieval. If an application attempts to retrieve the packet information before the server has sent its last packet, the IHeaderEnum call fails with an E_FAIL code.

The following code example shows an application retrieving header information sent by the OBEX server:

// Assume that pMyStream has already been initialized
IStream *pMyStream;
HRESULT hr;
OBEX_HEADER *obHeader = NULL;
ULONG ulHeadersFetched;
IHeaderEnum *pHeaderEnum = NULL;
while (someCondition == TRUE) 
{
  // Send data to the server
  CHAR szBuf[100];
  DWORD dwBufLen;
  DWORD dwWritten;
  hr = pMyStream->Write(szBuf, dwBufLen, &dwWritten);
  if (FAILED(hr))
    goto cleanup;
}
// Commit indicates last packet being sent from client
hr = pMyStream->Commit(0);
if (FAILED(hr))
  goto cleanup;
// Only after Commit, attempt to get data.
if ( FAILED (hr = pMyStream->QueryInterface(IID_IHeaderEnum,(void**)&pHeaderEnum)))
  goto cleanup;
// Query for the Obex headers
while (SUCCEEDED(pHeaderEnum->Next(1,&obHeader,&ulHeadersFetched))) 
{
  wprintf(L"Retrieved an obex header...\r\n");
}
cleanup: 
// perform cleanup as required

Community Additions

ADD
Show: