FindingApplications

From Nsnam
Revision as of 20:22, 16 June 2008 by Tjkopena (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Sometimes, you may want to find an application of a given type on a node. The @@Node@@ objects provides basic access to do this, and the @@TypeId@@ mechanism the ability to identify the application. If the application objects have @@TypeId@@s, then this simple loop will find an application:

  Ptr<Application> app;
  Ptr<MyApp> myapp = 0;
  for (uint32_t x = 0; x < node->GetNApplications(); x++) {
    app = node->GetApplication(x);
    if (app->GetInstanceTypeId() == MyApp::GetTypeId()) {
      myapp = dynamic_cast<MyApp *> (PeekPointer(app));
      break;
    }
  }

  if (myapp != 0) {
    // Do something MyApp specific with it...
  }

Note the specific syntax of the cast---the template is of the pointer, note a @@Ptr@@.