#include <ncpx_app.h>int NWRegisterNCPExtension( const char
NCPExtensionName, BYTE (
NCPExtensionHandler)( NCPExtensionClient
client, void
requestData, LONG requestDataLen, void
replyData, LONG
replyDataLen), void (
ConnectionEventHandler)( LONG connection, LONG eventType), void (
ReplyBufferManager)( NCPExtensionClient
client, void
replyBuffer), BYTE majorVersion, BYTE minorVersion, BYTE revision, void
queryData);
After an NCP extension has been registered, clients can access the NCP extension. The extension remains valid until the service-providing program deregisters the NCP extension.
NCPExtensionName is the name that the NCP extension uses as an identifier in the list of NCP extensions. NCP extension names are case-sensitive and must be unique. They have a maximum length of 32 bytes plus a NULL terminator.
When you call NWRegisterNCPExtension to register an NCP extension, three of the parameters are functions that are called as part of the Handler service. These parameters are NCPExtensionHandler, ConnectionEventHandler, and ReplyBufferManager.
NCPExtensionHandler points to a service routine (function) that is called when the client uses NWSendNCPExtensionRequest to call the NCP extension. In most cases, you want to provide an NCPX Handler. However, if your service can provide all information needed by updating the 32-byte queryData buffer, you do not need an NCPX Handler and can pass NULL for the parameter. The clients would then obtain the information in the queryData buffer by calling NWGetNCPExtensionInfo or NWScanNCPExtensions. This is a passive method of passing information. The NCP extension is not notified that an access has been made to its queryData.
The NCPExtensionHandler routine takes the following parameters:
typedef struct { LONG connection; LONG task; } NCPExtensionClient;
If a ReplyBufferManager was specified, this parameter points to the address of a pointer which the NCPX Handler sets to a valid buffer that it has created.
A better way for your NCPX Handler to return status information is to have it always return SUCCESSFUL and then use a ``status'' field in the replyData buffer. This technique guarantees that the status information is always from the NCPX Handler.
The ConnectionEventHandler callback parameter keeps track of when connections are freed or logged out. If keeping track of connection status is not important to you, you can pass NULL for the ConnectionEventHandler when you register the NCP extension.
The routine pointed to by ConnectionEventHandler has the following parameters:
Either the client has made a call to return its connection, or the server has cleared the connection (watchdog).
The client has made a call to log out.
ReplyBufferManager is a function that is used if the service-providing application wants to take care of reply buffer management for itself. This function takes the following parameters:
typedef struct { LONG connection; LONG task; } NCPExtensionClient;
The majorVersion, minorVersion, and revision parameters allow you to identify the version and revision of your service provider.
The queryData buffer is used by the service provider to return up to 32 bytes of information to the client. The pointer is also used by the registering NCPX application as the NCP extension handle, when calling NWDeRegisterNCPExtension(3xti_ncp).
Returning the contents of the update buffer to the client also provides a one-way, passive information passing scheme. Your service provider can use the buffer to supply periodic update information to its clients. This information can then be retrieved with a call to NWGetNCPExtensionInfo or NWScanNCPExtensions.
int HandlerMain(int argc, charargv[]) { int ccode; void
queryData;
NCPX_EventLoopState el_state;
/*********************************************/ /* Register the extension. */
ccode = NWRegisterNCPExtension("TEST EXTENSION", NCP_callback, ConnectionEvent_callback, NULL, /* No reply-buffer-manager callback. */ 1, /* major version */ 2, /* minor version */ 3, /* revision */ &queryData); if ( ccode != 0) { printf("%s had failure (ccode %d) registering NCP Extension.\n", ExecName, ccode); exit(1); }