/* You may freely copy, distribute and reuse the code in this example.
 * NeXT disclaims any warranty of any kind, expressed or implied, as to
 * its fitness for any particular use.
 */ 

#import "CallService.h"

@implementation CallService : CallController

/*
 * Purpose: notifies the application's delegate that the application
 * is ready to start.
 *
 * CallService implements this method to register itself as
 * the services delegate: the object that will handle requests
 * for the application's registered service.
 *
 */

- appDidInit:sender
{
    [[NXApp appListener] setServicesDelegate:self];
    return self;
}

/* 
 * Purpose: responds to a request for the application's service
 * 
 * Implemented by the application's services delegate to 
 * respond to requests for the registered service, "Find Caller."
 *
 */

- requestCall:pasteboard userData:(const char *)userData error:(char **)errorMessage 
{
    id	  success;
    char *data;
    int   dataLength;
    char *theName;

    [pasteboard types];
    success = 
	[pasteboard readType:NXAsciiPboardType data:&data length:&dataLength];
    if (success) {
	if (data && dataLength) {
	    theName = malloc(dataLength+1);
	    strncpy(theName, data, dataLength);
	    theName[dataLength]='\0';
	    [customerForm setStringValue:theName at:0];
	    [self retrieveCall:self];
	    [pasteboard deallocatePasteboardData:data length:dataLength];
	    free(theName); 
	}
	else {
	    NXRunAlertPanel("Search Failed", "Please select a customer name", 
		NULL, NULL, NULL);
	}
    }
    else *errorMessage = "Please select a customer name";
    return self;
}

@end
