/*
  The oSIP library implements the Session Initiation Protocol (SIP -rfc2543-)
  Copyright (C) 2001  Aymeric MOIZARD jack@atosc.org
  
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/


#include <osipparser2/osip_port.h>

#ifndef _INTERNAL_H_
#define _INTERNAL_H_

/**
 * Structure for payload management. Each payload element
 * represents one codec of a media line.
 * @defvar __payload_t
 */
typedef struct __payload __payload_t;

struct __payload
{
  char *payload;
  /*  char *port; this must be assigned by the application dynamicly */
  char *number_of_port;
  char *proto;
  char *c_nettype;
  char *c_addrtype;
  char *c_addr;
  char *c_addr_multicast_ttl;
  char *c_addr_multicast_int;
  /* rtpmap (rcvonly and other attributes are added dynamicly) */
  char *a_rtpmap;
};


/**
 * Allocate a payload element.
 * @param payload The payload.
 */
int __payload_init (__payload_t ** payload);
/**
 * Free a payload element.
 * @param payload The payload.
 */
void __payload_free (__payload_t * payload);


#ifdef OSIP_MT

/* Thread abstraction layer definition */

#ifdef __VXWORKS_OS__
#include <taskLib.h>
#endif

#if defined(WIN32) || defined(_WIN32_WCE)

#include <windows.h>
#endif

#if !defined(WIN32) && !defined(_WIN32_WCE) && defined(__PSOS__)
#include <psos.h>
#endif

/* HAVE_PTHREAD_H is not used any more! I keep it for a while... */
#if defined(HAVE_PTHREAD) || defined(HAVE_PTHREAD_H) || defined(HAVE_PTH_PTHREAD_H)
#include <pthread.h>
typedef pthread_mutex_t osip_mutex_t;
#endif

#ifdef __VXWORKS_OS__
typedef
{
  int id;
}
osip_thread_t;
#endif

#if defined(WIN32) || defined(_WIN32_WCE)
typedef struct
{
  HANDLE h;
  unsigned id;
}
osip_thread_t;

#elif defined(__PSOS__)
typedef struct
{
  unsigned long tid;
}
osip_thread_t;
#endif

#if !defined(WIN32) && !defined(_WIN32_WCE) && !defined(__VXWORKS_OS__) && !defined(__POS__)
#if defined(HAVE_PTHREAD) || defined(HAVE_PTHREAD_H) || defined(HAVE_PTH_PTHREAD_H)
typedef pthread_t osip_thread_t;
#else
#error no thread implementation found!
#endif
#endif


/* Semaphore and Mutex abstraction layer definition */

#if defined(WIN32) || defined(_WIN32_WCE)
#include <windows.h>
typedef struct
{
  HANDLE h;
}
osip_mutex_t;
typedef struct
{
  HANDLE h;
}
osip_sem_t;
#endif

#if (!(defined(WIN32) || defined (_WIN32_WCE)) && defined(__PSOS__))
#include <Types.h>
#include <os.h>
typedef struct
{
  UInt32 id;
}
osip_mutex_t;
typedef struct
{
  UInt32 id;
}
osip_sem_t;
#endif

#ifdef __VXWORKS_OS__
#include <semaphore.h>
#include <semLib.h>
typedef struct semaphore osip_mutex_t;
typedef sem_t osip_sem_t;
#endif

#ifdef __sun__
#include <semaphore.h>
#undef getdate
#include <synch.h>
#endif


#if defined(HAVE_SEMAPHORE_H) && !defined(__APPLE_CC__)
#include <semaphore.h>
#ifdef __sun__
#undef getdate
#include <synch.h>
#endif
/**
 * Structure for referencing a semaphore element.
 * @defvar osip_sem_t
 */
typedef sem_t osip_sem_t;

#elif defined(HAVE_SYS_SEM_H)
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
typedef struct
{
  int semid;
}
osip_sem_t;
#endif

#if (!defined(HAVE_SEMAPHORE_H) && !defined(HAVE_SYS_SEM_H) && !defined(WIN32) && !defined(_WIN32_WCE) && !defined(__PSOS__) && !defined(__VXWORKS_OS__))
#error No semaphore implementation found
#endif

#if defined(__PSOS__) || defined(__VXWORKS_OS__)

/* TODO */

#else

/**
 * Structure for referencing a condition variable element.
 * @defvar struct osip_cond
 */
#if defined(HAVE_PTHREAD) || defined(HAVE_PTH_PTHREAD_H)
typedef struct osip_cond
{
  pthread_cond_t cv;
} osip_cond_t;

#endif

#ifdef WIN32
typedef struct osip_cond
{
  struct osip_mutex *mut;
  struct osip_sem *sem;
} osip_cond_t;
#endif

#endif

#endif

#endif
