/*******************************************************************

Copyright (c) 2004 Open Mobile Alliance, Ltd.  All Rights Reserved.

This software is made available under the usage and distribution terms 
covered by the Common Public License 1.0 and by using this software you
are bound by the terms and conditions of the same.

EXCEPT AS EXPRESSLY SET FORTH IN THE COMMON PUBLIC LICENSE,
THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, 
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
   
Each recipient is solely responsible for determining the 
appropriateness of using and distributing this program and assumes 
all risks associated with its exercise of rights under the Common 
Public License, including but not limited to the risks and 
costs of program errors, compliance with applicable laws, 
damage to or loss of data, programs or equipment, and 
unavailability or interruption of operations.

********************************************************************/
#include <handle.h>
#include <stdlib.h>
#include <iConstants.h>
#include <transport.h>

/*
**************************************************************************
**
** Obex Handle
**
** ObxHandles are general handle structures for obex.  They are returned to
** callers when they request a 'handle'.
**
**************************************************************************
*/

/*
** Create a new handle.
*/
ObxHandle   *iobxHandleNew() {
   ObxHandle *newHandle = NULL;
   OBXDBGFLOW(("iobxHandleNew() entry.\n"));
   if ( (newHandle = (ObxHandle *)malloc( sizeof( ObxHandle ) )) ) {
      OBXDBGBUF(("iobxHandleNew() malloc, addr=0x%08x, len=%d.\n", newHandle, sizeof(ObxHandle) ));
      newHandle->transport = NULL;
      newHandle->maxPacketLen = OBEX_DEFAULT_PACKET_LENGTH;
      newHandle->lastRecv = 0;
      newHandle->lastSent = 0;
   }
   return newHandle;
}

/*
** Cleanup and destroy a passed handle.
*/
void        iobxHandleFree( ObxHandle *handle ) {
   OBXDBGFLOW(("iobxHandleFree() entry, handle=0x%08x\n", handle));
   if ( handle ) {
      if ( handle->transport ) {
         iobxTransportFree( handle->transport );
      }
      free( handle );
   }
}

/*
** Associate a transport with this handle.
*/
ObxRc          iobxHandleRegisterTransport( ObxHandle *handle, ObxTransport *transport ) {
   ObxRc rc = OBX_RC_ERR_BADPLIST;
   OBXDBGFLOW(("iobxHandleRegisterTransport() entry, handle=0x%08x\ttransport=0x%08x\n", handle, transport));
   if ( handle && transport ) {
      if ( handle->transport ) {
         iobxTransportFree( handle->transport );
      }
      handle->transport = transport;
   }
   return rc;
}




