WSRegisterCallbackFunction (C 関数)

WSRegisterCallbackFunction

WSENVオブジェクト,WSServiceRefオブジェクト,intオブジェクト,const char *オブジェクト,void *オブジェクトを引数として取り,voidを返す関数への関数ポインタを説明するWSTPのタイプである.

詳細

  • 関数WSRegisterLinkService()WSRegisterLinkServiceWithHostname()WSRegisterLinkServiceWithPortAndHostname()は,名前付きのサービスを通知するために,ネットワーク上のサービス登録操作を開始する.これらの関数は,登録操作を始めるだけで,すぐに返す.WSTPライブラリは,ネットワークサービス登録イベント上でプログラムをアップデートするために,WSRegisterCallbackFunctionとして入力された関数を通して,アプリケーションへの呼出しを非同期に行う.
  • WSRegisterCallbackFunctionは以下の形を持つ.
  • void function( WSENV e, WSServiceRef r, int flag, const char *name, void *context);
  • int引数には,ネットワーク上で起ったイベントの型を表すflagの値が含まれる.
  • flagの引数は,以下の値を持つことができる.
  • WSSDADDSERVICEconst char *引数には,ネットワーク上で現在使用可能な新しいサービスの名前へのポインタが含まれる
    WSSDREMOVESERVICEconst char *引数には,ネットワーク上でもはや使用できなくなったサービスの名前へのポインタが含まれる.この関数は,このコールバック関数を使うWSRegisterLinkService()関数で登録されたサービスへの削除フラッグのみを受け取る

例題

  (1)

#include "wstp.h"

void RegisterCallbackFunction(WSENV e, WSServiceRef r, int flags, const char *serviceName, void *context);

WSServiceRef startRegisterOperation(WSENV e, const char *serviceName)
{
    WSServiceRef theRef;
    WSLINK theLink = (WSLINK)0;
    int error;

    theLink = WSRegisterLinkService(e,
        serviceName,
        RegisterCallbackFunction, NULL /* Use the default
        network domain */, NULL, /* No context object for this
        example */, &theRef, &error);

    if(theLink == (WSLINK)0 || error != 0)
    { /* handle the error */ }

    return theRef;    
}


void RegisterCallbackFunction(WSENV e, WSServiceRef r, int flags, const char *serviceName, void *context)
{
    if(flags & WSSDADDSERVICE)
    { /* Handle successful service registration */ }
    else if(flags & WSSDREMOVESERVICE)
    { /* Handle service registration failure */ }
    else if(flags & WSSDREGISTERERROR)
    { /* Handle error in register operation */ }
}