samp.c File Reference

Top-level interface to the SAMP library. More...

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

Defines

#define SZ_CLIENT_LIST   1024

Functions

handle_t sampInit (String appName, String description)
 Initialize the SAMP interface.
void sampClose (handle_t handle)
 Close the SAMP interface and free resources.
int sampDebug (handle_t handle, int value)
 Set interface debug level.
int sampVerbose (handle_t handle, int value)
 Set interface debug level.
int sampStartup (handle_t handle)
 Startup the SAMP interface to send/receive messages.
int sampShutdown (handle_t handle)
 Shut down the active SAMP interface.
int samp_hubActive (handle_t handle)
 Determine if the Hub is active (i.e. connected).
int samp_setOpt (handle_t handle, char *opt, int value)
void samp_Metadata (handle_t handle, String field, String value)
 Set a metadata field value for the application.
void samp_Subscribe (handle_t handle, String mtype, void *userFunc)
 Subscribe to a given mtype.
void samp_Unsubscribe (handle_t handle, String mtype)
 Unsubscribe to a given mtype.
void samp_setCallMode (handle_t handle, int mode)
 Set the default calling mode (synch or asynch).
void samp_setSyncMode (handle_t handle)
 Set the calling mode to use synchronous messaging.
void samp_setASyncMode (handle_t handle)
 Set the calling mode to use asynchronous messaging.
void samp_setNotifyMode (handle_t handle)
 Set the calling mode to use notification messaging.
void samp_setMsgMode (handle_t handle, int mode)
 Set the message pattern to the specified mode.
void samp_setCallByRef (handle_t handle)
 Have interface call user handlers by reference.
void samp_setReplyCallback (handle_t handle, int *func)
 Set the Reply callback. samp_setReplyCallback (handle_t handle, int *func).
void samp_setResponseCallback (handle_t handle, int *func)
 Set the Response callback. samp_setResponseCallback (handle_t handle, int *func).
void samp_defaultReplyHandler (handle_t handle)
 The interface's default Reply handler.
void samp_deaultfResponseHandler (handle_t handle)
int samp_replyStatus (handle_t handle)
 Reply with the status of the last message sent.
void samp_setTimeout (handle_t handle, int timeout)
 Set the message timeout value (in seconds).
void samp_setAppName (handle_t handle, String name)
void samp_setAppVersion (handle_t handle, String version)
 Set the application name string.
int samp_mapClients (handle_t handle)
int samp_addClient (handle_t handle, String name, String id)
int samp_listClients (handle_t handle)
char * samp_getClients (handle_t handle)
int samp_removeClient (handle_t handle, String id)
Map samp_getOKMap ()
Map samp_getNullMap ()

Variables

SampsampP
handle_t sampH
Map nullMap
Map OK_Map
List nullList
Hubhub
int numHubs
long hubHandles [MAX_HUBS]


Detailed Description

Top-level interface to the SAMP library.

SAMP.C -- Top-level interface to the SAMP library.

samp = sampInit (appName, descr) sampClose (samp)

stat = sampStartup (samp) sampShutdown (samp)

samp_Metadata (samp, field, value) samp_Subscribe (samp, mtype, handler) samp_Unsubscribe (samp, mtype)

samp_setReplyCallback (samp, func) samp_setResponseCallback (samp, func) stat = samp_replyStatus (samp)

Utility Methods: samp_setSyncMode (samp) // Default samp_setASyncMode (samp) samp_setNotifyMode (samp) samp_setCallByRef (samp)

samp_setTimeout (samp, timeout) samp_setAppNmae (samp, version) samp_setAppVersion (samp, name)

samp_mapClients (handle_t handle) samp_addClient (handle_t handle, String name, String id) samp_removeClient (handle_t handle, String id)

Author:
Mike Fitzpatrick
Date:
7/10/09

Define Documentation

#define SZ_CLIENT_LIST   1024

SAMP_GETCLIENTS -- Get a list of clients as a character string as the PubID and Name separated by a space, one client per line.


Function Documentation

int samp_addClient ( handle_t  handle,
String  name,
String  id 
)

SAMP_ADDCLIENT -- Add a newly registered client to the list of known apps so we can do the public-private name translation.

References Samp::clients, Client::name, Samp::nclients, and SZ_NAME.

Referenced by samp_processHubEvent().

samp_defaultReplyHandler ( handle_t  handle  ) 

The interface's default Reply handler.

SAMP_DEFAULTREPLYHANDLER -- The interface's default Reply handler.

Parameters:
handle samp handle
Returns:
nothing

Map samp_getNullMap ( void   ) 

SAMP_GETNULLMAP -- Generate a 'Null' map we can return to the Hub.

References samp_newMap().

Map samp_getOKMap ( void   ) 

SAMP_GETOKMAP -- Generate an 'OK' map we can return to the Hub.

References nullMap, samp_newMap(), samp_setMapInMap(), and samp_setStringInMap().

samp_hubActive ( handle_t  handle  ) 

Determine if the Hub is active (i.e. connected).

SAMP_HUBACTIVE -- Determine if the Hub is active (i.e. connected).

Parameters:
handle user handle to samp struct
Returns:
nothing

References Samp::active.

int samp_listClients ( handle_t  handle  ) 

SAMP_LISTCLIENTS -- List the available clients to stdout.

References Samp::clients, Client::name, and Samp::nclients.

int samp_mapClients ( handle_t  handle  ) 

SAMP_MAPCLIENTS -- Map the public-ids of registered clients to the appName.

References Samp::clients, Client::name, Samp::nclients, samp_freeList(), samp_GetMetadata(), samp_GetRegisteredClients(), samp_getStringFromList(), samp_listLen(), and SZ_NAME.

Referenced by sampStartup().

samp_Metadata ( handle_t  handle,
String  field,
String  value 
)

Set a metadata field value for the application.

SAMP_METADATA -- Set a metadata field for the application. This will be sent to the Hub later in a declareMetadata() call.

Parameters:
handle samp handle
field metadata field to set (name, author, etc)
samp value of field
Returns:
nothing

References appMD::aKey, Samp::appVer, Hub::appVer, appMD::aVal, appMD::desc, Hub::description, Samp::description, appMD::docURL, Samp::hub, appMD::iconURL, Hub::meta, Samp::meta, appMD::nkeys, and sampTrace().

int samp_removeClient ( handle_t  handle,
String  id 
)

SAMP_REMOVECLIENT -- Remove a registered client from the list of known apps that do the public-private name translation.

References Samp::clients, Client::name, Samp::nclients, and SZ_NAME.

Referenced by samp_processHubEvent().

status samp_replyStatus ( handle_t  handle  ) 

Reply with the status of the last message sent.

SAMP_REPLYSTATUS -- Reply with the status of the last message sent.

May be used to 'poll' for a reponse from the caller in cases where use of a callback is a problem. Codes are: <0==ERR, 0==PENDING, 1==OK

Parameters:
samp samp struct ptr
Returns:
message status

Referenced by samp_Register().

samp_setAppVersion ( handle_t  handle,
String  version 
)

Set the application name string.

Set the application version string.

SAMP_SETAPPNAME -- Set the application name string.

Parameters:
handle samp handle
name application name
Returns:
nothing
SAMP_SETAPPVERSION -- Set the application version string.

Parameters:
handle samp handle
name application version
Returns:
nothing

References Hub::appVer, Samp::appVer, and Samp::hub.

samp_setASyncMode ( handle_t  handle  ) 

Set the calling mode to use asynchronous messaging.

SAMP_SETASYNCMODE -- Set the calling mode to use asynchronous messaging.

Parameters:
handle samp handle
Returns:
nothing

References Samp::msgMode.

samp_setCallByRef ( handle_t  handle  ) 

Have interface call user handlers by reference.

SAMP_SETCALLBYREF -- Have interface call user handlers by reference.

Parameters:
handle samp handle
Returns:
nothing

References Samp::handlerMode.

samp_setCallMode ( handle_t  handle,
int  mode 
)

Set the default calling mode (synch or asynch).

SAMP_SETCALLMODE -- Set the default calling mode (synch or asynch)

Parameters:
handle samp handle
mode call mode (synch or asynch)
Returns:
nothing

References Samp::msgMode.

samp_setMsgMode ( handle_t  handle,
int  mode 
)

Set the message pattern to the specified mode.

SAMP_SETMSGMODE -- Set the message pattern to the specified mode.

Parameters:
handle samp handle
mode message mode
Returns:
nothing

References Samp::msgMode.

samp_setNotifyMode ( handle_t  handle  ) 

Set the calling mode to use notification messaging.

SAMP_SETNOTIFYMODE -- Set the calling mode to use notification messaging.

Parameters:
handle samp handle
Returns:
nothing

References Samp::msgMode.

void samp_setReplyCallback ( handle_t  handle,
int *  func 
)

Set the Reply callback. samp_setReplyCallback (handle_t handle, int *func).

SAMP_SETREPLYCALLBACK -- Set the Reply callback.

Parameters:
handle samp handle
func callback for Reply message
Returns:
nothing

void samp_setResponseCallback ( handle_t  handle,
int *  func 
)

Set the Response callback. samp_setResponseCallback (handle_t handle, int *func).

SAMP_SETRESPONSECALLBACK -- Set the Response callback.

Parameters:
handle samp handle
func callback for message response
Returns:
nothing

samp_setSyncMode ( handle_t  handle  ) 

Set the calling mode to use synchronous messaging.

SAMP_SETSYNCMODE -- Set the calling mode to use synchronous messaging.

Parameters:
handle samp handle
Returns:
nothing

References Samp::msgMode.

samp_setTimeout ( handle_t  handle,
int  timeout 
)

Set the message timeout value (in seconds).

SAMP_SETTIMEOUT -- Set the message timeout value (in seconds).

Parameters:
handle samp handle
name application name
Returns:
nothing

References Samp::hub, and Hub::timeout.

samp_Subscribe ( handle_t  handle,
String  mtype,
void *  func 
)

Subscribe to a given mtype.

SAMP_SUBSCRIBE -- Subscribe to a given mtype.

Parameters:
handle user handle to samp struct
mtype mtype name
func callback function
Returns:
nothing

References Samp::nsubs, samp_getSampHandler(), samp_setSampHandler(), and samp_setUserHandler().

samp_Unsubscribe ( handle_t  handle,
String  mtype 
)

Unsubscribe to a given mtype.

SAMP_UNSUBSCRIBE -- Unsubscribe to a given mtype.

Parameters:
handle user handle to samp struct
mtype mtype name
Returns:
nothing

References Samp::nsubs, samp_DeclareSubscriptions(), Subs::sampFunc, and Subs::userFunc.

sampClose ( handle_t  handle  ) 

Close the SAMP interface and free resources.

SAMP_CLOSE -- Close the SAMP interface.

Parameters:
handle user handle to samp struct
Returns:
nothing

References Samp::hub, Samp::hubHandle, samp_freeHandle(), samp_hubClose(), sampTrace(), and Samp::verbose.

sampDebug ( handle_t  handle,
int  value 
)

Set interface debug level.

SAMPDEBUG -- Set interface debug level.

Parameters:
handle user handle to samp struct
value debug value
Returns:
nothing

References Samp::debug, and Samp::verbose.

handle sampInit ( String  name,
String  descr 
)

Initialize the SAMP interface.

SAMP_INIT -- Initialize the SAMP interface.

Parameters:
appName application name
description description of application
Returns:
samp handle

References nullList, nullMap, OK_Map, samp_hubOpen(), samp_newHandle(), samp_newList(), samp_newMap(), samp_serverPort(), samp_setMapInMap(), samp_setStringInMap(), sampH, and sampTrace().

sampShutdown ( handle_t  handle  ) 

Shut down the active SAMP interface.

SAMP_SHUTDOWN -- Shut down the active SAMP interface.

Parameters:
handle user handle to samp struct
Returns:
nothing

References Samp::active, Samp::hubHandle, samp_hubClose(), Samp::svrThread, and Samp::verbose.

Referenced by samp_processHubEvent().

sampStartup ( handle_t  handle  ) 

Startup the SAMP interface to send/receive messages.

SAMP_STARTUP -- Startup the SAMP interface to send/receive messages.

Parameters:
handle user handle to samp struct
Returns:
nothing

References Samp::active, Samp::clients, Samp::hub, Samp::hubHandle, Hub::id, Samp::mapClients, Client::name, Samp::nclients, samp_hubDeclareMetadata(), samp_hubDeclareSubscriptions(), samp_hubOpen(), samp_mapClients(), Samp::trace, and Samp::verbose.

sampVerbose ( handle_t  handle,
int  value 
)

Set interface debug level.

SAMPVERBOSE -- Set interface verbose level.

Parameters:
handle user handle to samp struct
value verbose value
Returns:
nothing

References Samp::verbose.


Variable Documentation

Hub* hub

long hubHandles[MAX_HUBS]

No. of available hubs

SAMP_OK Map struct

Referenced by sampInit().

int numHubs

HUB connection

handle_t sampH

SAMP struct pointer

Referenced by samp_processHubEvent(), samp_receiveCall(), and sampInit().


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