Stacking Protocols

After an application has opened and configured protocol services, it can stack them to create a device using lgo_Push(). When the application is finished with a device, the services are unstacked using lgo_Pop(). As the names push and pop suggest, a device is a "last-in-first-out" stack: it is constructed from the bottom up and dismantled from the top down. (Only services in the open state can be pushed and popped.) This process is illustrated in the dlg_AssembleStack() function in the dlaygo sample program.

Stacking services does not invalidate the CID of the services. The CIDs of all services opened by an application may be retained and the services may continue to be controlled directly using their CIDs. The CIDs remain valid until they are closed (or detached). See Service Control for more information.

Whether a particular service requires or even permits stacking depends on the protocol. For instance, LayGO's implementation of the HDLC/LAPB link protocol requires that it not be the lowest layer in a device. A LAPB service cannot become operational until it has been pushed onto another service. The reason is simple. LAPB processes frames which are transmitted over a physical medium, but it does not control the physical medium. It requires a service below which can physically transport frames . On the other hand, the X.21 bis physical layer does control a physical medium. It supports full-duplex communication without another protocol service pushed on top of it. For the same reason, it cannot be pushed onto any other layer. See Multiplexed Protocols for more information.

When a device is no longer needed, it should be disassembled working from the top down. Each service is removed from the top of the device by calling lgo_Pop() and then closed by calling lgo_Close(). This releases all the system resources used by the service. dlg_DisassembleStack() in the dlaygo sample program demonstrates this process.