Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > PHP/MySQL/Scripting

  • Print
  • + Share This
Like this article? We recommend

LspDirector Implementation

Listing 7 illustrates the LspDirector (mediator) class. The constructor takes an integer parameter anLspId that serves to differentiate the LSPs in the network. The WidgetChanged() method is invoked from the Widget base class whenever a widget is reconfigured (more on this later). The parameter passed into WidgetChanged() is a pointer to a widget called imAChangedWidget.

Inside WidgetChanged(), I have just two printf() statements for the two widget subclasses. In a real system, the updated widgets would have to be reflected in the LSP itself; for example, by tearing down the LSP and creating a replacement with the new widgets.

The CreateWidgets() method is used at construction time to create the two widgets and provide them with initial configurations. Finally, ChangePath() and ChangeQoSDetails() enable explicit changes to be made to the widget configurations.

Listing 7 LspDirector Implementation Code

LspDirector::LspDirector(int anLspId)
{
  lspId = anLspId;
}

LspDirector::~LspDirector(void)
{
}

void LspDirector::WidgetChanged(Widget* imAChangedWidget)
{
  if (imAChangedWidget == _lspPath)
    // Change the path used by the LSP
    printf("Director informed of change to LSP Path\n");
  else
    if (imAChangedWidget == _qosDescriptor)
      // Change the Qos resources used by the LSP
      printf("Director informed of change to QoS Resources\n");
}

void LspDirector::CreateWidgets()
{
  _lspPath = new PathWidget(this);
  _lspPath->CreateInitialPath("R2R3R4R5");

  _qosDescriptor = new QosWidget(this);
  _qosDescriptor->CreateInitialQoS("Assured Forwarding");
}

void LspDirector::ChangePath(char* newPath)
{
  _lspPath->ChangePath(newPath);
}

void LspDirector::ChangeQoSDetails(char* newQoS)
{
  _qosDescriptor->ChangeQoSDetails(newQoS);
}

Let’s now look at the Widget class implementation.

  • + Share This
  • 🔖 Save To Your Account