libmapper 2.4.12
mapper::Graph Class Reference

#include <mapper_cpp.h>

Inheritance diagram for mapper::Graph:
mapper::Object

Public Types

enum class  Event { OBJ_NEW = MPR_OBJ_NEW , OBJ_MOD = MPR_OBJ_MOD , OBJ_REM = MPR_OBJ_REM , OBJ_EXP = MPR_OBJ_EXP }
 
- Public Types inherited from mapper::Object
enum class  Status {
  UNDEFINED = MPR_STATUS_UNDEFINED , EXPIRED = MPR_STATUS_EXPIRED , NEW = MPR_STATUS_NEW , MODIFIED = MPR_STATUS_MODIFIED ,
  STAGED = MPR_STATUS_STAGED , ACTIVE = MPR_STATUS_ACTIVE , REMOVED = MPR_STATUS_REMOVED , HAS_VALUE = MPR_STATUS_HAS_VALUE ,
  NEW_VALUE = MPR_STATUS_NEW_VALUE , UPDATE_LOC = MPR_STATUS_UPDATE_LOC , UPDATE_REM = MPR_STATUS_UPDATE_REM , REL_UPSTRM = MPR_STATUS_REL_UPSTRM ,
  REL_DNSTRM = MPR_STATUS_REL_DNSTRM , INST_OFLW = MPR_STATUS_OVERFLOW , ANY = MPR_STATUS_ANY
}
 

Public Member Functions

 Graph (Type types=Type::OBJECT)
 
Graphset_iface (const str_type &iface)
 
std::string iface () const
 
Graphset_address (const str_type &group, int port)
 
std::string address () const
 
int poll (int block_ms=0) const
 
Graphstart (int block_ms=100)
 
Graphstop ()
 
const Graphsubscribe (const device_type &dev, Type types, int timeout)
 
const Graphsubscribe (Type types)
 
const Graphunsubscribe (const device_type &dev)
 
const Graphunsubscribe ()
 
template<typename T >
const Graphadd_callback (void(*h)(Graph &&, T &&, Graph::Event), Type types=Type::OBJECT)
 
const Graphremove_callback (void(*h)(Graph &&, Object &&, Graph::Event))
 
List< Devicedevices () const
 
List< Signalsignals () const
 
List< Mapmaps () const
 
const Graphpush () const
 
- Public Member Functions inherited from mapper::Object
 operator bool () const
 
Type type () const
 
Graph graph () const
 
int get_status () const
 
Objectreset_status ()
 
template<typename... Values>
Objectset_property (const Values... vals)
 
template<typename... Values>
Objectset_local_property (const Values... vals)
 
virtual Objectremove_property (Property prop)
 
virtual Objectremove_property (const str_type &key)
 
int num_props (bool staged=false) const
 
PropVal property (const str_type &key=NULL) const
 
PropVal property (Property prop) const
 
PropVal property (int idx) const
 

Detailed Description

Graphs are the primary interface through which a program may observe the network and store information about Devices and Signals that are present. Each Graph stores records of Devices, Signals, and Maps, which can be queried.

Member Enumeration Documentation

◆ Event

enum class mapper::Graph::Event
strong

The set of possible graph events, used to inform callbacks.

Enumerator
OBJ_NEW 

New record has been added to the graph.

OBJ_MOD 

The existing record has been modified.

OBJ_REM 

The existing record has been removed.

OBJ_EXP 

The graph has lost contact with the remote entity.

Constructor & Destructor Documentation

◆ Graph()

mapper::Graph::Graph ( Type types = Type::OBJECT)
inline

Create a peer in the libmapper distributed graph.

Parameters
typesSets whether the graph should automatically subscribe to information about Signals and Maps when it encounters a previously-unseen Device.

Member Function Documentation

◆ add_callback()

template<typename T >
const Graph & mapper::Graph::add_callback ( void(* )(Graph &&, T &&, Graph::Event),
Type types = Type::OBJECT )
inline

Register a callback for when an Object record is added, updated, or removed.

Parameters
hCallback function.
typesBitflags setting the type of information of interest. Can be a combination of Type values.
Returns
Self.

◆ address()

std::string mapper::Graph::address ( ) const
inline

Retrieve the multicast url currently in use.

Returns
A string specifying the multicast url in use.

◆ devices()

List< Device > mapper::Graph::devices ( ) const
inline

Return a List of all Devices.

Returns
A List of Devices.

◆ iface()

std::string mapper::Graph::iface ( ) const
inline

Return a string indicating the name of the network interface in use.

Returns
A string containing the name of the network interface.

◆ maps()

List< Map > mapper::Graph::maps ( ) const
inline

Return a List of all Maps.

Returns
A List of Maps.

◆ poll()

int mapper::Graph::poll ( int block_ms = 0) const
inline

Synchronize a Graph object with the distributed graph.

Parameters
block_msThe number of milliseconds to block, or 0 for non-blocking behavior.
Returns
The number of handled messages.

◆ push()

const Graph & mapper::Graph::push ( ) const
inlinevirtual

Push "staged" property changes out to the distributed graph.

Returns
Self.

Reimplemented from mapper::Object.

◆ remove_callback()

const Graph & mapper::Graph::remove_callback ( void(* )(Graph &&, Object &&, Graph::Event))
inline

Remove an Object record callback from the Graph service.

Parameters
hCallback function.
Returns
Self.

◆ set_address()

Graph & mapper::Graph::set_address ( const str_type & group,
int port )
inline

Specify the multicast group and port to use.

Parameters
groupA string specifying the multicast group to use.
portThe multicast port to use.
Returns
Self.

◆ set_iface()

Graph & mapper::Graph::set_iface ( const str_type & iface)
inline

Specify the network interface to use.

Parameters
ifaceA string specifying the name of the network interface to use.
Returns
Self.

◆ signals()

List< Signal > mapper::Graph::signals ( ) const
inline

Return a List of all Signals.

Returns
A List of Signals.

◆ start()

Graph & mapper::Graph::start ( int block_ms = 100)
inline

Start automatically synchronizing a Graph object in a separate thread.

Parameters
block_msThe number of milliseconds to block on each iteration, or <0 to process all incoming messages.
Returns
Self.

◆ stop()

Graph & mapper::Graph::stop ( )
inline

Stop automatically synchronizing a Graph object in a separate thread.

Returns
Self.

◆ subscribe() [1/2]

const Graph & mapper::Graph::subscribe ( const device_type & dev,
Type types,
int timeout )
inline

Subscribe to information about a specific Device.

Parameters
devThe Device of interest.
typesBitflags setting the type of information of interest. Can be a combination of MPR_DEV, MPR_SIG_IN, MPR_SIG_OUT, MPR_SIG, MPR_MAP_IN, MPR_MAP_OUT, MPR_MAP, or simply MPR_OBJ for all information.
timeoutThe desired duration in seconds for this subscription. If set to -1, the graph will automatically renew the subscription until it is freed or this function is called again.
Returns
Self.

◆ subscribe() [2/2]

const Graph & mapper::Graph::subscribe ( Type types)
inline

Subscribe to information about all discovered Devices.

Parameters
typesBitflags setting the type of information of interest. Can be a combination of MPR_DEV, MPR_SIG_IN, MPR_SIG_OUT, MPR_SIG, MPR_MAP_IN, MPR_MAP_OUT, MPR_MAP, or simply MPR_OBJ for all information.
Returns
Self.

◆ unsubscribe() [1/2]

const Graph & mapper::Graph::unsubscribe ( )
inline

Cancel all subscriptions.

Returns
Self.

◆ unsubscribe() [2/2]

const Graph & mapper::Graph::unsubscribe ( const device_type & dev)
inline

Unsubscribe from information about a specific Device.

Parameters
devThe Device of interest.
Returns
Self.