/* 
 * machine.c
 *
 * x-kernel v3.3
 *
 * Copyright (c) 1993,1991,1990,1996  Arizona Board of Regents
 *
 * $Revision: 1.2 $
 * $Date: 1996/02/01 15:20:28 $
 */

/*****************************************************************************/
#include <sys/time.h>
#include <signal.h>
#include "xk_debug.h"
#include "upi.h"
#include "platform.h"

extern int SignalsPossible;
extern Semaphore master_lock;

extern int clock_ih(void);

struct itimerval i_value, i_zero;

#define handlerresulttype void
typedef handlerresulttype (*handlertype)();

int inInterrupt;
void cancelSignalHandler(int);
void installSignalHandler(int sock, int (*f)());
void xholdsignals(int);
void xreleasesignals(int);
void findsocket(void);
void fixFileMask(void);
void dispatch(int);
void onfault(handlertype);
void sig_int_handler(void);
void init_clock(void);
int read_clock(long *);
void definehandler(int, handlertype);
void signal_handler(int, handlertype);
void event_handler(void);


/* don't know how many sockets we should allow for */
/* update this in [udp,tcp].c too */
#define NUMSOCKETSICANUSE 30
extern  int     errno;

void
cancelSignalHandler(int sock)
{
}

void
installSignalHandler(int sock, int (*f)())
{
}

void
xholdsignals(int sock)
{
}

void
xreleasesignals(int sock)
{
}

void
findsocket(void)
{
}

void
fixFileMask(void)
{
}

void
dispatch(int interruptNo)
{
}


void
onfault(handlertype h)
{
}


void
sig_int_handler(void)
{

}


void
init_clock(void)
{
  definehandler(SIGPIPE, SIG_IGN);
  definehandler(SIGINT, (handlertype) sig_int_handler);
  definehandler(SIGIO,  (handlertype) dispatch);
  definehandler(SIGURG,  (handlertype) dispatch);

  /* start event processor */
  CreateProcess((int (*)())event_handler, THREAD_MINPRIO, 1, 0); /*LSB*/

  return;
}


#ifdef READ_CLOCK
int
read_clock(long *msec)        /* returns the number of msec */
                              /* since sometime in late 1986 */
{
  struct  timeval   time;
  struct  timezone  zone;

  gettimeofday(&time, &zone);
  *msec = (time.tv_sec - 500000000)*1000 + (time.tv_usec / 1000);
  return(0);
}
#endif READ_CLOCK


void
definehandler(int sig, handlertype handler)
{
}

void signal_handler(int sigid, handlertype handler)
{
}

int state;
int state_int;

void event_handler(void)
{
  xk_master_unlock();

  for (;;) {
    xk_master_lock();
    clock_ih();
    xk_master_unlock();
    threadYield();
  }
}

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