Function Publishing Example

The following is an example of function publishing taken from the Position constraint controller example, in the file \\Samples\\Controllers\\Position_cnstrnt.cpp. The IPosConstPosition class represents an interface to the Position constraint. This class inherits from FPMixinInterface which means that it can expose it functionality using the Function Publishing.

The following code declares identifiers for each of the exposed functions.

enum {  
  get_num_targets,    
  get_node,      
  get_target_weight,    
  set_target_weight,    
  append_target,     
  delete_target
};   

The following code in the main body of the constraint creates the function map.

// Function Map for function publishing system
BEGIN_FUNCTION_MAP
FN_0(get_num_targets,      TYPE_INT,   GetNumTargets);
FN_1(get_node,            TYPE_INODE, GetNode, TYPE_INDEX);
FN_1(get_target_weight,    TYPE_FLOAT, GetTargetWeight, TYPE_INDEX);
FN_2(set_target_weight,    TYPE_BOOL,  SetTargetWeight, TYPE_INDEX, TYPE_FLOAT);
FN_2(append_target,        TYPE_BOOL,  AppendTarget, TYPE_INODE, TYPE_FLOAT);
FN_1(delete_target,        TYPE_BOOL,  DeleteTarget, TYPE_INDEX);
END_FUNCTION_MAP

The following is a list of virtual functions exposed to external developers:

virtual int     GetNumTargets()=0;
virtual INode*  GetNode(int targetNumber)=0;
virtual float   GetTargetWeight(inttargetNumber)=0;
virtual BOOL    SetTargetWeight(inttargetNumber, float weight)=0;
virtual BOOL    AppendTarget(INode *target, float weight=50.0)=0;
virtual BOOL    DeleteTarget(int selection)=0;

In the main body of the code in position_cnstrnt.cpp we find:

static  FPInterfaceDesc pos_constraint_interface(
  POS_CONSTRAINT_INTERFACE,
  _T("constraints"),
  0,
  &posCD,
  0,
   IPosConstPosition::get_num_targets,   
    _T("getNumTargets"), 0, TYPE_INDEX, 0, 0,
   IPosConstPosition::get_node,          
    _T("getNode"),  0, TYPE_INODE, 0, 1,
    _T("nodeNumber"),  0, TYPE_INDEX,
   IPosConstPosition::get_target_weight,  
    _T("getWeight"), 0, TYPE_FLOAT, 0, 1,
    _T("targetNumber"),  0, TYPE_INDEX,
   IPosConstPosition::set_target_weight,  
    _T("setWeight"), 0, TYPE_BOOL, 0, 2,
    _T("targetNumber"),  0, TYPE_INDEX,
    _T("weight"),  0, TYPE_FLOAT,
   IPosConstPosition::append_target,    
    _T("appendTarget"), 0, TYPE_BOOL, 0, 2,
    _T("target"),  0, TYPE_INODE,
    _T("weight"),  0, TYPE_FLOAT,
   IPosConstPosition::delete_target,    
    _T("deleteTarget"), 0, TYPE_BOOL, 0, 1,
    _T("targetNumber"), 0, TYPE_INDEX,
  end
);

.