sampHub.c File Reference

Methods related to the SAMP Hub interface. More...

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#include <ctype.h>
#include "samp.h"

Defines

#define HUB_DBG   (getenv("HUB_DBG")!=NULL||access("/tmp/HUB_DBG",F_OK)==0)

Functions

handle_t samp_hubOpen (Samp *sampP)
 Discover and open a connection to the SAMP Hub.
int samp_hubClose (handle_t handle)
 Close a connection to the Hub.
int samp_hubRunning (void)
List samp_getAvailableHubs (handle_t handle)
 Get a list of available Hubs.
char * samp_getActiveHubName (handle_t handle)
int samp_getActiveHub (handle_t handle)
int samp_hubInit (handle_t handle, char *appName, char *descr)
int samp_processHubEvent (String mtype, Map params)
 Determine the type of Hub event mtype.
int samp_hubEvent (String mtype)
 Determine the type of Hub event mtype.
int samp_hubRegister (Hub *hub)
 Send a Register message to the Hub.
int samp_hubUnRegister (Hub *hub)
 Send a UnRegister message to the Hub.
int samp_hubSendShutdown (Hub *hub)
 Send a samp.app.event.shutdown message to the Hub.
int samp_hubSetXmlrpcCallback (Hub *hub)
 Set the client callback and send to Hub.
int samp_hubPing (Hub *hub)
 Ping the Hub to see if it is alive.
int samp_hubDeclareMetadata (Hub *hub)
 Declare "standard" metadata to the Hub.
int samp_hubDeclareSubscriptions (Hub *hub)
 Declare mtype subscriptions to the Hub.

Variables

Hubhub = (Hub *) NULL
int numHubs = 0
handle_t hubHandles [MAX_HUBS]
pthread_mutex_t samp_mutex = PTHREAD_MUTEX_INITIALIZER
SampsampP
int numSamps
handle_t sampHandles [MAX_SAMPS]
Map nullMap


Detailed Description

Methods related to the SAMP Hub interface.

SAMPHUB.C -- Methods related to the SAMP Hub interface.

Author:
Mike Fitzpatrick
Date:
7/10/09

Function Documentation

List samp_getAvailableHubs ( handle_t  handle  ) 

Get a list of available Hubs.

SAMP_GETAVAILABLEHUBS -- Get a list of available Hubs

Parameters:
handle hub handle
Returns:
List of hub handles

int samp_hubClose ( handle_t  handle  ) 

Close a connection to the Hub.

SAMP_HUBCLOSE -- Close a connection to the Hub.

Parameters:
handle hub handle
Returns:
unregister status

References appMD::aKey, appMD::aVal, Hub::meta, appMD::nkeys, samp_freeHandle(), and samp_hubUnRegister().

Referenced by sampClose(), and sampShutdown().

int samp_hubDeclareMetadata ( Hub hub  ) 

Declare "standard" metadata to the Hub.

SAMP_DECLAREMETADATA -- Declare "standard" metadata to the Hub.

Parameters:
hub hub struct pointer
Returns:
status

References appMD::aKey, appMD::aVal, Hub::description, appMD::docURL, appMD::iconURL, Hub::id, Hub::meta, appMD::nkeys, and Hub::privateKey.

Referenced by samp_DeclareMetadata(), and sampStartup().

int samp_hubDeclareSubscriptions ( Hub hub  ) 

Declare mtype subscriptions to the Hub.

SAMP_HUBDECLARESUBSCRIPTIONS -- Declare mtype subscriptions to the Hub.

Parameters:
hub hub struct pointer
Returns:
status

References Hub::id, Samp::nsubs, nullMap, Hub::privateKey, Hub::samp, samp_freeMap(), and Subs::userFunc.

Referenced by samp_DeclareSubscriptions(), and sampStartup().

int samp_hubEvent ( String  mtype  ) 

Determine the type of Hub event mtype.

SAMP_HUBEVENT -- Determine the type of Hub event mtype.

Parameters:
mtype mtype string
Returns:
Hub event code or -1 if not found

References HUB_SHUTDOWN.

Referenced by samp_processHubEvent().

handle_t samp_hubOpen ( Samp sampP  ) 

Discover and open a connection to the SAMP Hub.

SAMP_HUBOPEN -- Discover and open a connection to the SAMP Hub.

Parameters:
samp Same structure
Returns:
hub handle

References Hub::appId, Samp::appVer, Hub::appVer, appMD::desc, Hub::description, Samp::description, Hub::id, Hub::meta, Hub::samp, samp_hubRegister(), samp_hubSetXmlrpcCallback(), samp_newHandle(), samp_P2H(), Hub::timeout, and Hub::url.

Referenced by sampInit(), and sampStartup().

int samp_hubPing ( Hub hub  ) 

Ping the Hub to see if it is alive.

SAMP_HUBPING -- Ping the Hub to see if it is alive.

Parameters:
hub hub struct pointer
Returns:
status

References Hub::id, and Hub::privateKey.

Referenced by samp_Ping().

int samp_hubRegister ( Hub hub  ) 

Send a Register message to the Hub.

SAMP_HUB_REGISTER -- Send a Register message to the Hub.

Parameters:
hub hub struct pointer
Returns:
status

References Hub::hubId, Hub::id, Hub::privateKey, Hub::secret, and Hub::selfId.

Referenced by samp_hubOpen().

int samp_hubRunning ( void   ) 

SAMP_HUBRUNNING -- See whether a Hub is running. The test simply checks the existence of a Hub lockfile.

References SZ_NAME.

int samp_hubSendShutdown ( Hub hub  ) 

Send a samp.app.event.shutdown message to the Hub.

SAMP_HUBSENDSHUTDOWN -- Send a samp.app.event.shutdown message to the Hub.

Parameters:
hub hub struct pointer
Returns:
status

References Hub::id, Hub::privateKey, and samp_nullResponse().

int samp_hubSetXmlrpcCallback ( Hub hub  ) 

Set the client callback and send to Hub.

SAMP_HUBSETXMLRPCCALLBACK -- Set the client callback and send to Hub

Parameters:
hub hub struct pointer
Returns:
status

References Hub::id, Hub::privateKey, and samp_serverPort().

Referenced by samp_hubOpen().

int samp_hubUnRegister ( Hub hub  ) 

Send a UnRegister message to the Hub.

SAMP_HUBUNREGISTER -- Send a UnRegister message to the Hub.

Parameters:
hub hub struct pointer
Returns:
status

References Hub::id, and Hub::privateKey.

Referenced by samp_hubClose(), and samp_UnRegister().

int samp_processHubEvent ( String  mtype,
Map  params 
)

Determine the type of Hub event mtype.

SAMP_HUBEVENT -- Determine the type of Hub event mtype.

Parameters:
mtype mtype string
params message parameter Map
Returns:
non-zero value if a Hub event was processed

References HUB_SHUTDOWN, samp_addClient(), samp_hubEvent(), samp_mutex, samp_P2H(), samp_removeClient(), sampH, and sampShutdown().

Referenced by samp_receiveNotification().


Variable Documentation

Hub* hub = (Hub *) NULL

handle_t hubHandles[MAX_HUBS]

No. of available hubs

SAMP handle

int numHubs = 0

HUB connection

pthread_mutex_t samp_mutex = PTHREAD_MUTEX_INITIALIZER

lock so we can update struct

Referenced by samp_processHubEvent().


Generated on Wed Feb 27 21:10:15 2013 for SAMP Client Library by  doxygen 1.5.9