#import <appkit/appkit.h>
#import "IReceiveListener.h"
#import <mach/mach.h>
#import <mach/message.h>
#import <servers/netname.h>
extern port_t name_server_port;
extern id NXResponsibleDelegate();
@implementation  IReceiveListener :Listener
{}
static NXRemoteMethod *remoteMethods = NULL;
#define REMOTEMETHODS 4
+ initialize 
/* */
{
    if (!remoteMethods) {
	remoteMethods =
	(NXRemoteMethod *) malloc((REMOTEMETHODS+1)*sizeof(NXRemoteMethod));
	remoteMethods[0].key = 
	@selector(receiveArticle:length:);
	remoteMethods[0].types = "ci";
	remoteMethods[1].key = 
	@selector(sendArticleWithMessageID:);
	remoteMethods[1].types = "c";
	remoteMethods[2].key = 
	@selector(makeMimeIconWindowAtpointX:pointY:offsetX:offsetY:sourceWindow:);
	remoteMethods[2].types = "iiiii";
	remoteMethods[3].key = 
	@selector(requestForPost:sourceWindow:);
	remoteMethods[3].types = "ci";
	remoteMethods[REMOTEMETHODS].key = NULL;
    }
    return self;
}
-(int)receiveArticle : (char *) data
	length : (int) length
/* */
{
    id _NXd;
    if (_NXd = NXResponsibleDelegate(self,
	@selector(receiveArticle:length:)))
	return [_NXd receiveArticle : data
		length : length];
    return -1;
}

-(int)sendArticleWithMessageID : (char *) messageID
/* */
{
    id _NXd;
    if (_NXd = NXResponsibleDelegate(self,
	@selector(sendArticleWithMessageID:)))
	return [_NXd sendArticleWithMessageID : messageID];
    return -1;
}

-(int)makeMimeIconWindowAtpointX : (int) x
	pointY : (int) y
	offsetX : (int) offx
	offsetY : (int) offy
	sourceWindow : (int) wnum
/* */
{
    id _NXd;
    if (_NXd = NXResponsibleDelegate(self,
	@selector(makeMimeIconWindowAtpointX:pointY:offsetX:offsetY:sourceWindow:)))
	return [_NXd makeMimeIconWindowAtpointX : x
		pointY : y
		offsetX : offx
		offsetY : offy
		sourceWindow : wnum];
    return -1;
}

-(int)requestForPost : (char *) newsgroups
	sourceWindow : (int) wnum
/* */
{
    id _NXd;
    if (_NXd = NXResponsibleDelegate(self,
	@selector(requestForPost:sourceWindow:)))
	return [_NXd requestForPost : newsgroups
		sourceWindow : wnum];
    return -1;
}

- (int) performRemoteMethod : (NXRemoteMethod *) method
                  paramList : (NXParamValue *) paramList {
/* */
    switch (method - remoteMethods) {
    case 0:
	return [self receiveArticle : paramList[0].bval.p
		length : paramList[1].ival];
    case 1:
	return [self sendArticleWithMessageID : paramList[0].bval.p];
    case 2:
	return [self makeMimeIconWindowAtpointX : paramList[0].ival
		pointY : paramList[1].ival
		offsetX : paramList[2].ival
		offsetY : paramList[3].ival
		sourceWindow : paramList[4].ival];
    case 3:
	return [self requestForPost : paramList[0].bval.p
		sourceWindow : paramList[1].ival];
    default:
	return [super performRemoteMethod : method paramList : paramList];
    }
}
- (NXRemoteMethod *) remoteMethodFor: (SEL) aSel {
/* */
    NXRemoteMethod *rm;
    if (rm = NXRemoteMethodFromSel(aSel,remoteMethods))
        return rm;
    return [super remoteMethodFor : aSel];
}
@end
