/*
 * select.c
 *
 * x-kernel v3.3
 *
 * Copyright (c) 1993,1991,1990,1996  Arizona Board of Regents
 *
 * $Revision: 1.2 $
 * $Date: 1996/01/29 22:25:04 $
 */

#include "xkernel.h"
#include "select.h"
#include "select_i.h"


/* 
 * select -- The select protocol determines the upper
 * protocol ID at open/openenable time by calling relProtNum.
 */

#ifdef __STDC__

static void		getProtFuncs( Protl );
static Sessn		selectOpen( Protl, Protl, Protl, Part * );
static XkReturn	selectOpenDisable( Protl, Protl, Protl, Part * );
static XkReturn 	selectOpenEnable( Protl, Protl, Protl, Part * );

#else

static void		getProtFuncs();
static Sessn		selectOpen();
static XkReturn	selectOpenDisable();
static XkReturn 	selectOpenEnable();

#endif /* __STDC__ */


void
select_init( self )
    Protl self;
{
    xTrace0(selectp, TR_GROSS_EVENTS, "SELECT init");
    if (!xIsProtl(xGetProtlDown(self, 0))) {
	xTrace0(selectp, TR_ERRORS,
		"SELECT could not find down protocol -- not initializing");
	return;
    }
    getProtFuncs(self);
    selectCommonInit(self);
}


static Sessn
selectOpen( self, hlp, hlpType, p )
    Protl	self, hlp, hlpType;
    Part    	*p;
{
    long	hlpNum;
    
    xTrace0(selectp, TR_MAJOR_EVENTS, "SELECT open");
    if ( (hlpNum = relProtNum(hlpType, self)) == -1 ) {
	return ERR_SESSN;
    }
    return selectCommonOpen(self, hlp, hlpType, p, hlpNum);
}


static XkReturn
selectOpenEnable( self, hlp, hlpType, p )
    Protl   self, hlp, hlpType;
    Part    *p;
{
    long	hlpNum;

    xTrace0(selectp, TR_MAJOR_EVENTS, "SELECT openEnable");
    if ( (hlpNum = relProtNum(hlpType, self)) == -1 ) {
	return XK_FAILURE;
    }
    return selectCommonOpenEnable(self, hlp, hlpType, p, hlpNum);
}


static XkReturn
selectOpenDisable( self, hlp, hlpType, p )
    Protl   self, hlp, hlpType;
    Part    *p;
{
    long	hlpNum;

    xTrace0(selectp, TR_MAJOR_EVENTS, "SELECT openDisable");
    if ( (hlpNum = relProtNum(hlpType, self)) == -1 ) {
	return XK_FAILURE;
    }
    return selectCommonOpenDisable(self, hlp, hlpType, p, hlpNum);
}



static void
getProtFuncs( p )
    Protl 	p;
{
    p->controlprotl = selectControlProtl;
    p->open = selectOpen;
    p->openenable = selectOpenEnable;
    p->opendisable = selectOpenDisable;
    p->calldemux = selectCallDemux;
    p->demux = selectDemux;
}
