Restored options for AppServers (and implemented registration)

This commit is contained in:
Pierre Pronchery 2014-04-27 01:20:04 +08:00
parent 9c29bc3cef
commit f97c4ab165
4 changed files with 53 additions and 26 deletions

View File

@ -53,15 +53,16 @@ static int _appserver_helper_message(void * data, AppTransport * transport,
/* public */
/* functions */
/* appserver_new */
AppServer * appserver_new(const char * app, char const * name)
AppServer * appserver_new(AppServerOptions options, const char * app,
char const * name)
{
return appserver_new_event(app, name, NULL);
return appserver_new_event(options, app, name, NULL);
}
/* appserver_new_event */
AppServer * appserver_new_event(char const * app, char const * name,
Event * event)
AppServer * appserver_new_event(AppServerOptions options, char const * app,
char const * name, Event * event)
{
AppServer * appserver;
@ -81,6 +82,10 @@ AppServer * appserver_new_event(char const * app, char const * name,
appserver_delete(appserver);
return NULL;
}
/* register the server if requested */
if(options & ASO_REGISTER)
/* XXX should we really ignore errors? */
apptransport_server_register(appserver->transport, app);
return appserver;
}

View File

@ -141,7 +141,6 @@ static void _new_helper(AppTransport * transport, AppTransportMode mode,
/* apptransport_new_app */
static String * _new_app_name(char const * app, char const * name);
static String * _new_app_query(char const * app);
static String * _new_app_transport(String ** name);
AppTransport * apptransport_new_app(AppTransportMode mode,
@ -188,29 +187,10 @@ static String * _new_app_name(char const * app, char const * name)
name = getenv(var);
string_delete(var);
if(name == NULL)
return _new_app_query(app);
return apptransport_lookup(app);
return string_new(name);
}
static String * _new_app_query(char const * app)
{
const char session[] = "Session";
String * name = NULL;
AppClient * appclient;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, app);
#endif
if(strcmp(app, session) == 0)
return NULL;
if((appclient = appclient_new(session, NULL)) == NULL)
return NULL;
/* we can ignore errors */
appclient_call(appclient, (void **)&name, "lookup", app);
appclient_delete(appclient);
return name;
}
static String * _new_app_transport(String ** name)
{
String * p;
@ -274,6 +254,27 @@ String const * apptransport_client_get_name(AppTransportClient * client)
/* useful */
/* apptransport_lookup */
String * apptransport_lookup(char const * app)
{
const char session[] = "Session";
String * name = NULL;
AppClient * appclient;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, app);
#endif
if(strcmp(app, session) == 0)
return NULL;
if((appclient = appclient_new(session, NULL)) == NULL)
return NULL;
/* we can ignore errors */
appclient_call(appclient, (void **)&name, "lookup", app);
appclient_delete(appclient);
return name;
}
/* apptransport_client_send */
int apptransport_client_send(AppTransport * transport, AppMessage * message,
int acknowledge)
@ -287,6 +288,24 @@ int apptransport_client_send(AppTransport * transport, AppMessage * message,
}
/* apptransport_server_register */
int apptransport_server_register(AppTransport * transport, char const * app)
{
int ret;
AppClient * appclient;
int res = -1;
if((appclient = appclient_new("Session", NULL)) == NULL)
return -1;
ret = appclient_call(appclient, (void **)&res, "register", app,
transport->name);
ret = (ret == 0 && res == 0) ? 0 : -1;
/* FIXME really keep alive until the transport exits */
appclient_delete(appclient);
return ret;
}
/* apptransport_server_send */
int apptransport_server_send(AppTransport * transport,
AppTransportClient * client, AppMessage * message)

View File

@ -49,11 +49,14 @@ String const * apptransport_get_transport(AppTransport * transport);
String const * apptransport_client_get_name(AppTransportClient * client);
/* useful */
String * apptransport_lookup(char const * app);
/* ATM_CLIENT */
int apptransport_client_send(AppTransport * transport, AppMessage * message,
int acknowledge);
/* ATM_SERVER */
int apptransport_server_register(AppTransport * transport, char const * app);
int apptransport_server_send(AppTransport * transport,
AppTransportClient * client, AppMessage * message);

View File

@ -52,7 +52,7 @@ int main(int argc, char * argv[])
default:
return _usage();
}
if((appserver = appserver_new(app, name)) == NULL)
if((appserver = appserver_new(0, app, name)) == NULL)
{
error_print("appserver");
return 2;