/mnt/hgfs/jamie_On_My_Mac/store/version_control/svn/integralive/library/trunk/Integra/integra_server.h File Reference

#include <stdarg.h>
#include "Integra/integra_instance.h"
#include "Integra/integra_model.h"
#include "Integra/integra_error.h"
#include "Integra/integra_path.h"
#include "Integra/integra_connection.h"
#include "Integra/integra_bridge_host.h"

Go to the source code of this file.

Data Structures

struct  ntg_class_list_
struct  ntg_server_
struct  ntg_client_
 Data type to store client details. More...

Defines

#define RESPONSE_LABEL   "response"
#define BASE_URL   "db.integralive.org:80/"
#define ADMIN_URL   BASE_URL "admin/"
#define NTG_NULL_STRING   "None"

Typedefs

typedef struct ntg_class_list_ ntg_class_list
typedef struct ntg_server_ ntg_server
typedef struct ntg_client_ ntg_client
 Data type to store client details.
typedef void *(* ntg_server_callback )(ntg_server *, int, va_list)
typedef void *(* ntg_bridge_callback )(int argc, void *argv)
 Callback function that gets passed to the module host when the server is started.

Functions

ntg_class_listntg_classlist (const ntg_server *server)
 Get the list of available classes from the server.
ntg_definitionntg_classinfo (ntg_server *server, const char *class_name)
 Get the definition for a given class.
ntg_attribute_listntg_attributes (const ntg_server *server, const char *class_name)
 Get the attribute definitions for a given class.
char * ntg_new (const ntg_server *server, const char *class_name, const char *instance_name, const ntg_path *path)
 Create a new instance of a class on the server.
ntg_error_code ntg_delete (ntg_server *server, const ntg_path *path)
 Delete an instance of a class on the server.
ntg_error_code ntg_rename (const ntg_server *server, const ntg_path *path, const char *name)
 Rename an instance of a class on the server.
ntg_error_code ntg_save (const ntg_server *server, const ntg_path *path, const char *file_path)
 Save all nodes including and below a given node on the server to a path on the filesystem.
ntg_error_code ntg_load (const ntg_server *server, const char *file_path, const ntg_path *path)
 Load all nodes including and below a given node from the filesystem beneath the path given to the given node on the server.
ntg_error_code ntg_move (const ntg_server *server, const ntg_path *instance_path, const ntg_path *parent_path)
 Move an instance of a class on the server.
ntg_error_code ntg_set (const ntg_server *server, const ntg_path *attribute_path, const ntg_value *value)
 Set the value of an attribute of an instance on the server.
ntg_valuentg_get (const ntg_server *server, const ntg_path *path)
 Get the value of an attribute of an instance on the server.
ntg_node_listntg_nodelist (const ntg_server *server, const ntg_path *path)
 Get the list of paths to instances on the server under a given node.
void ntg_updates (const ntg_server *server, int index)
 Get all commands since 'index' from command queue.
int ntg_stateindex (const ntg_server *server)
 Get the most recent state index from the command queue.
ntg_error_code ntg_runscript (ntg_server *server, const char *script)
 Connect two attributes on the server.
ntg_serverntg_server_new (void)
void * ntg_server_do (ntg_server_callback, const int argc,...)
void * server_receive_callback (ntg_id id, unsigned int port, const int argc, const ntg_value *message, void(*bridge_send_callback)(const ntg_port *, const ntg_value *))
 Callback function corresponing to ih_callback in the bridge interface (see integra_bridge.h ntg_bridge_interface->ih_callback.
ntg_bridge_callback ntg_server_run (const char *bridge_file, const int port)
 Create a new Integra server.
ntg_definitionntg_get_definition_by_name (const ntg_server *server, const char *name)
char * ntg_get_type_by_id (const ntg_server *server, const int id)
char ntg_type_code_from_type_string (const char *type)
char * ntg_get_scope_by_id (const ntg_server *server, const int id)
char * ntg_get_control_attribute_by_id (ntg_server *server, const int id)
char * ntg_get_control_by_control_attribute_id (ntg_server *server, const int id)
char * ntg_get_scale_by_id (ntg_server *server, const int id)
ntg_module_attributentg_get_module_attribute_by_id (const ntg_server *server, const int id)
ntg_default_valuentg_get_default_value_by_id (ntg_server *server, const int id)
char * ntg_get_unit_by_id (ntg_server *server, const int id)
char * ntg_get_control_by_id (ntg_server *server, const int id)
int ntg_register (ntg_server *server, const char *ip, const int port)
ntg_instancentg_server_get_root (const ntg_server *server)
 Get the root of the instance graph.
void ntg_server_set_root (ntg_server *server, ntg_instance *root)
ntg_node_listntg_server_get_nodelist (const ntg_server *server, ntg_instance *container, ntg_path *parent_path, ntg_node_list *nodelist)
 Get the list of nodes under a container instance as an array.
ntg_attribute_listntg_server_get_class_attributes (const ntg_server *server, const char *class_name, ntg_attribute_list *attribute_list)
 Recursively get the attributes for a class.
ntg_error_code ntg_server_update_connection (ntg_server *server, const ntg_instance *connection_instance, const ntg_instance_attribute *instance_attribute)
 Update a connection in the connection list.
ntg_error_code ntg_server_new_connection (ntg_server *server, const ntg_instance *connection_instance)
 New connection in the connection list.
ntg_error_code ntg_server_delete_connection (ntg_server *server, const ntg_instance *connection_instance)
 Delete a connection in the connection list.
ntg_error_code ntg_server_delete_orphaned_connections (ntg_server *server)
 Delete orphaned connections on the server This function also disconnects the connection in the module host if needed.
ntg_error_code ntg_server_instance_delete (ntg_server *server, ntg_instance *instance)
 Remove an instance from the server.
ntg_error_code ntg_server_fix_connections (ntg_server *server, ntg_instance *instance, const char *name)
 Fix connections that point to instance so that the point to 'name'.

Define Documentation

#define ADMIN_URL   BASE_URL "admin/"

Referenced by ntg_server_new().

#define BASE_URL   "db.integralive.org:80/"
#define NTG_NULL_STRING   "None"
#define RESPONSE_LABEL   "response"

Typedef Documentation

typedef void*(* ntg_bridge_callback)(int argc, void *argv)

Callback function that gets passed to the module host when the server is started.

This function is the mechanism by which data is passed *back* from the module host to the bridge, and then on to the instance host. It enables messages to be passed 'natively' to the instance host, without involving OSC.

typedef struct ntg_client_ ntg_client

Data type to store client details.

typedef struct ntg_server_ ntg_server
typedef void*(* ntg_server_callback)(ntg_server *, int, va_list)

Function Documentation

ntg_attribute_list* ntg_attributes ( const ntg_server server,
const char *  class_name 
)

Get the attribute definitions for a given class.

Parameters:
*server,: a pointer to a struct of type ntg_server
*class_name,: a NULL terminated string giving the name of the class
Returns:
a pointer to an ntg_attribute_list struct containing the attribute definition for all of the class's attributes a pointer to NULL is returned if an error occurs

References ntg_server_get_class_attributes().

Referenced by ntg_connect(), ntg_disconnect(), and ntg_new().

ntg_definition* ntg_classinfo ( ntg_server server,
const char *  class_name 
)

Get the definition for a given class.

Parameters:
*server,: a pointer to a struct of type ntg_server.
*class_name,: a NULL terminated string giving the name of the class
Returns:
a pointer to an ntg_definition struct containing data on the class a pointer to NULL is returned if an error occurs

References ntg_get_definition_by_name().

ntg_class_list* ntg_classlist ( const ntg_server server  ) 

Get the list of available classes from the server.

Parameters:
*server,: a pointer to a struct of type ntg_server.
Returns:
a pointer to an ntg_class_list struct containing class list as strings a pointer to NULL is returned if an error occurs

References _ntg_model::allocated_definitions, ntg_class_list_::classes, ntg_server_::classlist, _ntg_model::definitions, ntg_server_::model, ntg_class_list_::n_classes, _ntg_model::n_definitions, and _ntg_definition::name.

Referenced by ntg_server_new().

ntg_error_code ntg_delete ( ntg_server server,
const ntg_path path 
)

Delete an instance of a class on the server.

Parameters:
*server,: a pointer to a struct of type ntg_server
*path,: a pointer to a struct of type ntg_path giving the elements in the path to the given instance. The path array must include the instance itself, i.e. if we are deleting an instance called 'FooBar1', the path array might be ['Project1', 'Block1', 'FooBar1']
Returns:
a struct of type ntg_error_code. If the function succeeded, the return value will be NTG_NO_ERROR possible return values for error status are given in integra_error.h

References ntg_server_::bridge, ntg_server_::connection_list, DB_SERVER, DEBUG_POST(), NTG_ERROR, ntg_instance_find_by_path(), NTG_NO_ERROR, ntg_server_delete_orphaned_connections(), ntg_server_get_root(), and ntg_server_instance_delete().

ntg_value* ntg_get ( const ntg_server server,
const ntg_path path 
)

Get the value of an attribute of an instance on the server.

Parameters:
*server,: a pointer to a struct of type ntg_server in the path to the given instance. The path array must include the instance itself, i.e. if we are getting the value of an attribute in instance called 'FooBar1', the path array might be ['Project1', 'Block1', 'FooBar1']
*path,: a pointer to a struct of type ntg_path giving the elements in the path to the given attribute. The path array must include the attribute itself, i.e. if we are getting the value of an attribute called 'blah' in an instance called 'FooBar1', the path array might be ['Project1', 'Block1', 'FooBar1', 'blah']. If the path is invalid, or the final element doesn't correspond to an attribute an error code of NTG_PATH_ERROR will be returned
Returns:
a pointer to a struct of type ntg_value. The type (see integra_types.h) of the value returned is guaranteed to match the type of the attribute as given in the attribute definition a pointer to NULL is returned if an error occurs

References ntg_path_::elems, ntg_path_::n_elems, ntg_instance_attribute_find_by_name(), ntg_instance_find_by_path(), NTG_NO_ERROR, ntg_path_free(), ntg_path_pop_element(), ntg_path_validate(), ntg_print_error(), ntg_server_get_root(), and ntg_instance_attribute_::value.

char* ntg_get_control_attribute_by_id ( ntg_server server,
const int  id 
)
char* ntg_get_control_by_control_attribute_id ( ntg_server server,
const int  id 
)
char* ntg_get_control_by_id ( ntg_server server,
const int  id 
)
ntg_default_value* ntg_get_default_value_by_id ( ntg_server server,
const int  id 
)

References _ntg_model::default_values, and ntg_server_::model.

Referenced by ntg_new().

ntg_definition* ntg_get_definition_by_name ( const ntg_server server,
const char *  name 
)
ntg_module_attribute* ntg_get_module_attribute_by_id ( const ntg_server server,
const int  id 
)
char* ntg_get_scale_by_id ( ntg_server server,
const int  id 
)
char* ntg_get_scope_by_id ( const ntg_server server,
const int  id 
)
char* ntg_get_type_by_id ( const ntg_server server,
const int  id 
)
char* ntg_get_unit_by_id ( ntg_server server,
const int  id 
)
ntg_error_code ntg_load ( const ntg_server server,
const char *  file_path,
const ntg_path path 
)

Load all nodes including and below a given node from the filesystem beneath the path given to the given node on the server.

Parameters:
*server,: a pointer to a struct of type ntg_server
*file_path,: a pointer to a string representing the path to the file on the filesystem
*path,: a pointer to a struct of type ntg_path giving the elements in the path to the parent instance under which the new instance will be loaded. i.e. if we are loading an instance inside Project1 the path would be ['Project1']. A NULL value indicates that the new instance will be loaded under the server root node
Returns:
a struct of type ntg_error_code. If the function succeeded, the return value will be NTG_NO_ERROR possible return values for error status are given in integra_error.h

References NTG_FAILED.

ntg_error_code ntg_move ( const ntg_server server,
const ntg_path instance_path,
const ntg_path parent_path 
)

Move an instance of a class on the server.

Parameters:
*server,: a pointer to a struct of type ntg_server
*instance_path,: a pointer to a struct of type ntg_path giving the elements in the path to the given instance. The path array must include the instance itself, i.e. if we are deleting an instance called 'FooBar1', the path array might be ['Project1', 'Block1', 'FooBar1']
*parent_path,: a pointer to the new parent path. the source instance and all children will be moved underneath the parent node
Returns:
a struct of type ntg_error_code. If the function succeeded, the return value will be NTG_NO_ERROR possible return values for error status are given in integra_error.h

References NTG_FAILED.

char* ntg_new ( const ntg_server server,
const char *  class_name,
const char *  instance_name,
const ntg_path path 
)

Create a new instance of a class on the server.

Parameters:
*server,: a pointer to a struct of type ntg_server
*class_name,: a string representing the name of the class to be instantiated
*instance_name,: the name of the new instance. Instance names must be unique within containing scope. If an aready exisiting instance name is provided, then an error code will be returned. If NULL is provided, a unique instance name will be generated and returned
*path,: the path for the containing scope. this identifies the instance names of the containers enclosing our new instance. e.g. ['Project1', 'Block1']
Returns:
a pointer to a char giving a NULL terminated string that represents the name of the new instance a pointer to NULL is returned if an error occurs

References ntg_attribute_list_::attributes, ntg_server_::bridge, DB_SERVER, DEBUG_POST(), ntg_path_::elems, _ntg_definition::id, _ntg_module_attribute::id_default_value, _ntg_attribute::id_module_attribute, _ntg_attribute::id_type, ntg_bridge_interface::module_load, ntg_attribute_list_::n_attributes, ntg_path_::n_elems, _ntg_attribute::name, _ntg_definition::name, ntg_instance_attribute_::next, ntg_attributes(), ntg_get_default_value_by_id(), ntg_get_definition_by_name(), ntg_get_module_attribute_by_id(), ntg_get_type_by_id(), ntg_instance_add(), ntg_instance_add_attributes(), ntg_instance_attribute_find_by_name(), ntg_instance_attribute_send_value(), ntg_instance_attribute_set_default_value(), ntg_instance_find_by_name(), ntg_instance_find_by_path(), ntg_instance_increment_count(), ntg_instance_new(), ntg_instance_set_class_id(), ntg_instance_set_name(), ntg_print_error(), ntg_server_get_root(), ntg_server_new_connection(), ntg_type_code_from_type_string(), ntg_bridge_interface::post, and _ntg_definition::system.

ntg_node_list* ntg_nodelist ( const ntg_server server,
const ntg_path path 
)

Get the list of paths to instances on the server under a given node.

Parameters:
*server,: a pointer to a struct of type ntg_server
*path,: a pointer to a struct of type ntg_path giving the elements in the path to the given parent. The path gives the root of the nodelist, so if we want ALL nodes on the server, an empty path should be given. For all nodes under the container: Project1, the path array should be ['Project1']
Returns:
a pointer to a struct of type ntg_node_list, which gives all of the paths under a given node as n_nodes ntg_path arrays a pointer to NULL is returned if an error occurs

References DB_SERVER, DEBUG_POST(), ntg_node_list_::n_nodes, ntg_node_list_::nodes, ntg_instance_find_by_path(), ntg_malloc(), ntg_print_error(), ntg_server_get_nodelist(), and ntg_server_get_root().

int ntg_register ( ntg_server server,
const char *  ip,
const int  port 
)
ntg_error_code ntg_rename ( const ntg_server server,
const ntg_path path,
const char *  name 
)

Rename an instance of a class on the server.

Parameters:
*server,: a pointer to a struct of type ntg_server
*path,: a pointer to a struct of type ntg_path giving the elements in the path to the given instance. The path array must include the instance itself, i.e. if we are renaming an instance called 'FooBar1', the path array might be ['Project1', 'Block1', 'FooBar1']
*name,: a pointer to a string representing the new name of the instance
Returns:
a struct of type ntg_error_code. If the function succeeded, the return value will be NTG_NO_ERROR possible return values for error status are given in integra_error.h

References NTG_ERROR, ntg_instance_find_by_path(), ntg_instance_set_name(), NTG_NO_ERROR, ntg_server_fix_connections(), and ntg_server_get_root().

ntg_error_code ntg_runscript ( ntg_server server,
const char *  script 
)

Connect two attributes on the server.

Parameters:
*server,: a pointer to a struct of type ntg_server
Note:
ntg_connect() is an alias for the following (pseudo-code): ntg_new(server, "Connection", "Connection1", ["Project1", "Block1"]); ntg_set(server, ["Project1", "Block1", "Connection1"], "sourcePath", "TapDelay1") ntg_set(server, ["Project1", "Block1", "Connection1"], "sourceAttribute", "out1") ntg_set(server, ["Project1", "Block1", "Connection1"], "targetPath", "LowPass1") ntg_set(server, ["Project1", "Block1", "Connection1"], "targetAttribute", "in1") Run a script on the server
Parameters:
*server,: a pointer to a struct of type ntg_server
*script,: a pointer to a NULL terminated string containing the script to be executed
Note:
the script follows Lua syntax

Connect two attributes on the server.

Note, the function returns immediately, and it doesn't matter whether the server is locked or not when calling.

Parameters:
server Server object created by ntg_server_new
string A string containing scripting code The string can contain several lines separated by lineshifts.

References DB_SERVER, DEBUG_POST(), NTG_ERROR, ntg_lua_eval(), NTG_NO_ERROR, and ntg_print_error().

ntg_error_code ntg_save ( const ntg_server server,
const ntg_path path,
const char *  file_path 
)

Save all nodes including and below a given node on the server to a path on the filesystem.

Parameters:
*server,: a pointer to a struct of type ntg_server
*path,: a pointer to a struct of type ntg_path giving the elements in the path to the given instance. The path array must include the instance itself, i.e. if we are saving an instance called 'FooBar1', the path array might be ['Project1', 'Block1', 'FooBar1']
*file_path,: a pointer to a string representing the path to the file on the filesystem
Returns:
a struct of type ntg_error_code. If the function succeeded, the return value will be NTG_NO_ERROR possible return values for error status are given in integra_error.h

References NTG_FAILED.

ntg_error_code ntg_server_delete_connection ( ntg_server server,
const ntg_instance connection_instance 
)
ntg_error_code ntg_server_delete_orphaned_connections ( ntg_server server  ) 
void* ntg_server_do ( ntg_server_callback  ,
const int  argc,
  ... 
)
ntg_error_code ntg_server_fix_connections ( ntg_server server,
ntg_instance instance,
const char *  name 
)
ntg_attribute_list* ntg_server_get_class_attributes ( const ntg_server server,
const char *  class_name,
ntg_attribute_list attribute_list 
)
ntg_node_list* ntg_server_get_nodelist ( const ntg_server server,
ntg_instance container,
ntg_path parent_path,
ntg_node_list nodelist 
)
ntg_instance* ntg_server_get_root ( const ntg_server server  ) 
ntg_error_code ntg_server_instance_delete ( ntg_server server,
ntg_instance instance 
)
ntg_server* ntg_server_new ( void   ) 
ntg_error_code ntg_server_new_connection ( ntg_server server,
const ntg_instance connection_instance 
)
ntg_bridge_callback ntg_server_run ( const char *  bridge_file,
const int  port 
)
void ntg_server_set_root ( ntg_server server,
ntg_instance root 
)

References ntg_server_::root.

Referenced by ntg_server_run().

ntg_error_code ntg_server_update_connection ( ntg_server server,
const ntg_instance connection_instance,
const ntg_instance_attribute instance_attribute 
)
ntg_error_code ntg_set ( const ntg_server server,
const ntg_path attribute_path,
const ntg_value value 
)

Set the value of an attribute of an instance on the server.

Parameters:
*server,: a pointer to a struct of type ntg_server
*path,: a pointer to a struct of type ntg_path giving the elements in the path to the given attribute. The path array must include the attribute itself, i.e. if we are setting the value of an attribute called 'blah' in an instance called 'FooBar1', the path array might be ['Project1', 'Block1', 'FooBar1', 'blah']. If the path is invalid, or the final element doesn't correspond to an attribute an error code of NTG_PATH_ERROR will be returned
*value,: a pointer to a struct of type ntg_value containing the value we are setting the attribute to. The supported types for value are given in integra_model.h however, the type of *value must match the type of the attribute being set as given by the attribute definition. Otherwise an NTG_TYPE_ERROR will be returned
Returns:
a struct of type ntg_error_code. If the function succeeded, the return value will be NTG_NO_ERROR possible return values for error status are given in integra_error.h

References ntg_server_::bridge, _ntg_model::definitions, ntg_path_::elems, ntg_server_::model, ntg_path_::n_elems, _ntg_definition::name, NTG_ERROR, NTG_FAILED, ntg_instance_attribute_find_by_name(), ntg_instance_attribute_send_value(), ntg_instance_attribute_set_value(), ntg_instance_find_by_path(), NTG_NO_ERROR, ntg_path_free(), ntg_path_pop_element(), ntg_path_validate(), ntg_print_error(), ntg_server_get_root(), ntg_server_update_connection(), and _ntg_definition::system.

int ntg_stateindex ( const ntg_server server  ) 

Get the most recent state index from the command queue.

char ntg_type_code_from_type_string ( const char *  type  ) 
void ntg_updates ( const ntg_server server,
int  index 
)

Get all commands since 'index' from command queue.

void* server_receive_callback ( ntg_id  id,
unsigned int  port,
const int  argc,
const ntg_value message,
void(*)(const ntg_port *, const ntg_value *)  bridge_send_callback 
)

Callback function corresponing to ih_callback in the bridge interface (see integra_bridge.h ntg_bridge_interface->ih_callback.

References ntg_port_::module_id.

Referenced by ntg_server_run().


Generated on Tue Jan 5 14:02:29 2010 for LibIntegra by  doxygen 1.6.1