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 Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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@@.