hconnect

Synopsis

module hconnect{
int+read _direction;
string+read _*offer_name;
string+read _*accept_name;
string+read _*offer;
string+read _*accept;
int+read _skip_levels;
int+read _order;
int+write _accepted;
  };

Description

The hconnect module allows connections to be made automatically as objects are instanced. The connections are made between subobjects of the instanced object and an existing instance of the hconnect that is an ancestor of the instanced object. For some networks, this can make network construction easier.

You use this module when an object's location in the object hierarchy is an indication that a particular connection is to be made. For example, you can define a macro that contains a user interface panel so that as you drop widgets into this macro, the widgets parent connections are connected to the panel.

With this module, connections can be made either from the parent to the child or from the child to the parent as specified by the direction parameter. For each connection, one hconnect module serves as the child to "offer" a connection and another hconnect module serves as the parent "accepting" the connection. An individual hconnect module can serve as a parent, child, or both.

The offer_name parameter specifies the pathname relative to the hconnect module of the subobject that should be connected. The accept_name parameter specifies the pathname relative to the parent module

A hierarchical class specification allows flexible classification of the offer and accept objects so that connections can be targeted to an appropriate parent. For example, you can define particular types of subobjects that are to connect to particular types of parents.

Input

direction

If this value is a 0, the child is connected to the parent. If the value is a 1, the parent is connected to the child.

offer_name

If this hconnect module should serve as a child offering a connection, set this parameter to a string defining the pathname relative to the hconnect module of the child's parameter that is to be connected.

accept_name

If this hconnect module should serve as a parent accepting a connection, set this parameter to a string defining the pathname relative to the hconnect module of the parent's parameter to be connected.

offer

If this hconnect module should serve as a child, this parameter specifies the types of parents to which this hconnect module should connect. The offer parameter of this hconnect module must match the accept parameter of the parent hconnect module for a connect to be made.

accept

If this hconnect module should serve as a parent, this parameter specifies the types of children to which this hconnect module should connect. The accept parameter of this hconnect module must match the offer parameter of the child hconnect module for a connection to be made.

skip_levels

It is sometimes necessary to have the child skip some number of levels in the hierarchy before it starts searching for a parent hconnect module. This is typically used to prevent the child from connecting to another hconnect module defined in the same macro. In this case, set this number to an integer specifying the number of levels in the hierarchy that should be skipped before searching for the parent hconnect module.

order

If the direction parameter is a 1, this parameter defines the order in which connections are inserted into the connection list of the accepting object. An object with a smaller order value is inserted into the list before an object with a larger order value. If order is not set, the order of the objects in the list is not defined.

accepted

This output parameter is set to 1 in the child hconnect object if the connection is made and 0 if no connection was found.

Defining global parents

By default, as the child searches for a parent to connect to, it looks for hconnect modules that are direct ancestors of the child. This includes any immediate parent of the hconnect module and all peers of all parents. It is sometimes useful to define the parent hconnect module as a child of one of the peers of a parent. In this case, you can set the hconnect property to 2 on the peer of your parent so that the hconnect module can be found.

offer/accept strings

These strings are specified as a hierarchical list of classes. Each class is specified as a simple white-space delimited identifier with an optional set of sub-classes. Two class strings match if they have a single class that matches. If a class in both the offer and accept have a sub-class specification, one of the classes in the sub-class specification must also match. For example:

offer

accept

match?

"class1"

"class1"

yes

"class2 class1"

"class1"

yes

"class1"

"class2"

no

"class1"

"class1 class2"

yes

"class1 (sub1 sub2)"

"class1 (sub1)"

yes

"class1 (sub1 sub2)"

"class1"

yes

"class1 (sub2 sub3)"

"class1 (sub4 sub5)"

no

"class1 (sub1)"

"class1 (!sub1)"

no

Example

This example shows how to use hconnect to define both child and parent widgets that are to be connected when the child is instanced as a subobject of the parent. To use this example, load these objects into a library and instance the EXtest object.

UIslider+GMOD.hconnect EXslider {
direction = 0; // connection goes from child to parent
offer = "widget"; // connect to "widget" class
offer_name = "parent"; // connect parent subobject of EXslider
};
macro EXpanel {
UIshell+GMOD.hconnect parent_shell {
accept = "widget"; // accept all offer = "widget" children
accept_name = "."; // connect to parent_shell itself
};
};
application EXtest {
// Creates a shell that has a slider in it.
// The connection dynamically is:
//
// EXslider.parent => EXpanel;
//
EXpanel EXpanel {
EXslider EXslider;
};
};

This example shows how to define a menu bar macro and a set of children objects that install themselves into th
This example shows how to define a menu bar macro and a set of children objects that install themselves into the parent. To use this example, load these objects into a library and instance the EXmenu_bar object.


UIcmd+GMOD.hconnect EXcmd {
direction = 1; // connect from parent to child
offer = "cmd"; // connect to all cmds
offer_name = "."; // connect this object to the parent
};
UIcmdList+GMOD.hconnect EXcmdList {
direction = 1;
accept = "cmd cmdList";
// accepts either cmds or cmdLists
accept_name = "cmdList";
offer = "cmdList";
offer_name = ".";
};
macro EXmenu_bar {
// hconnect=2 causes us to search subobjects for
// hconnect modules
macro CmdLists<hconnect=2> {
UIshell shell {
_________menu => <-.menu_bar;
};
// menu_bar.cmdList => {CmdLists.File, CmdLists.Edit};
EXcmdList menu_bar {
_________direction = 1;
___// only accept cmdLists
___accept = "cmdList";
};
______EXcmdList File {
___accept = "cmd (File)";
};
EXcmdList Edit {
___accept = "cmd (Edit)";
};
};
// connection is made from File.cmdList => {New_File};
EXcmd New_File {
offer = "cmd (File)";
};
// connection is made from Edit.cmdList => {New_Edit};
EXcmd New_Edit {
offer = "cmd (Edit)";
};
};