Пример #1
0
bool Arbiter::setSlotBehaviors(Basic::PairStream* const x)
{
   bool ok = true;

   // First, make sure they are all behaviors
   {
      Basic::List::Item* item = x->getFirstItem();
      while (item != nullptr && ok) {
         Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
         item = item->getNext();
         Behavior* b = dynamic_cast<Behavior*>( pair->object() );
         if (b == nullptr) {
            // Item is NOT a behavior
            std::cerr << "setSlotBehaviors: slot: " << *pair->slot() << " is NOT of a Behavior type!" << std::endl;
            ok = false;
         }
      }
   }

   // next, add behaviors to our list
   if (ok) {
      Basic::List::Item* item = x->getFirstItem();
      while (item != nullptr) {
         Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
         item = item->getNext();
         Behavior* b = static_cast<Behavior*>(pair->object());
         addBehavior(b);
      }
   }

   return ok;
}
Пример #2
0
//------------------------------------------------------------------------------
// processSubpages() -- process our subpages; make sure they are all of
//	type Page (or derived from it)and tell them that we are their
//	container.
//------------------------------------------------------------------------------
bool Page::processSubpages()
{
    bool ok = true;
    if (subpages != 0) {
        // Make sure we have only Pages and tell all of the pages
        // that we are their container.
        const Basic::List::Item* item = subpages->getFirstItem();
        while (ok && item != 0) {
            Basic::Pair* p = (Basic::Pair*) item->getValue();
            item = item->getNext();
            Page* g = dynamic_cast<Page*>(p->object());
            if (g != 0) {
                // It MUST be of type Page
                g->container(this);
            }
            else {
                // Delete components that are not of Page type
                if (isMessageEnabled(MSG_ERROR)) {
                    std::cerr << "Page::processSubpages(): " << *p->slot() << " is not a Page!" << std::endl;
                }
                ok = false;
            }
        }
    }
    return ok;
}
Пример #3
0
//------------------------------------------------------------------------------
// setSlotNetworks() -- Set our list of networks
//------------------------------------------------------------------------------
bool Station::setSlotNetworks(Basic::PairStream* const a)
{
    bool ok = true;

    // Remove the old networks list
    if (networks != 0) {
        // we are no longer the container for these networks
        for (Basic::List::Item* item = networks->getFirstItem(); item != 0; item = item->getNext()) {
            Basic::Pair* pair = (Basic::Pair*)(item->getValue());
            NetIO* p = (NetIO*)( pair->object() );
            p->container(0);
        }
    }

    // Set our network list pointer
    networks = a;

    // Make sure the new network list is setup correctly
    if (networks != 0) {
        for (Basic::List::Item* item = networks->getFirstItem(); item != 0; item = item->getNext()) {
            Basic::Pair* pair = (Basic::Pair*)(item->getValue());
            NetIO* p = dynamic_cast<NetIO*>( pair->object() );
            if (p != 0) {
                // We are this network's container
                p->container(this);
            }
            else {
                // Not of the proper type
                std::cerr << "Player::setSlotNetworks: network at slot \"" << pair->slot() << "\" is not of class type NetIO" << std::endl;
                ok = false;
            }
        }
    }
    return ok;
}
Пример #4
0
//------------------------------------------------------------------------------
// setOwnshipPlayer() -- set this player as our ownship
//------------------------------------------------------------------------------
bool Station::setOwnshipPlayer(Player* const newOS)
{
    // Is it already own ownship?  Yes, then nothing else to do.
    if (newOS == ownship) return true;

    // When we're just setting a null(0) ownship ...
    if (newOS == 0) {
        // Unref the old player
        if (ownshipName != 0) { ownshipName->unref(); ownshipName = 0; }
        if (ownship != 0) {
            ownship->event(ON_OWNSHIP_DISCONNECT);
            ownship->unref();
            ownship = 0;
        }
        return true;
    }

    // Look for this ownship in our list of players
    bool set = false;
    Basic::PairStream* pl = sim->getPlayers();
    if (pl != 0) {
        Basic::List::Item* item = pl->getFirstItem();
        while (item != 0 && !set) {
            Basic::Pair* pair = dynamic_cast<Basic::Pair*>(item->getValue());
            if (pair != 0) {
                Player* ip = dynamic_cast<Player*>( pair->object() );
                if (ip == newOS && ip->isLocalPlayer()) {
                    // Unref the old stuff
                    if (ownshipName != 0) { ownshipName->unref(); ownshipName = 0; }
                    if (ownship != 0) {
                        ownship->event(ON_OWNSHIP_DISCONNECT);
                        ownship->unref();
                        ownship = 0;
                    }
                    // Ok, we found the player -- make it our ownship
                    ownship = newOS;
                    ownship->ref();
                    ownshipName = pair->slot();
                    ownshipName->ref();
                    ownship->event(ON_OWNSHIP_CONNECT);
                    set = true;
                }
            }
            item = item->getNext();
        }

        pl->unref();
        pl = 0;
    }
    return set;
}
Пример #5
0
bool Station::setSlotOutTheWindow(Basic::PairStream* const list)
{
   Basic::PairStream* newList = 0;

   // Make sure the new list only has OTW type objects
   if (list != 0) {
      for (Basic::List::Item* item = list->getFirstItem(); item != 0; item = item->getNext()) {
            Basic::Pair* pair = (Basic::Pair*)(item->getValue());
            Otw* p = dynamic_cast<Otw*>( pair->object() );
            if (p != 0) {
            if (newList == 0) {
               newList = new Basic::PairStream();
            }
            newList->put(pair);  // Add this OTW to our new OTW list
                p->container(this);
            }
         else if (isMessageEnabled(MSG_WARNING)) {
                // Not of the proper type
                std::cerr << "Player::setOutTheWindow: OTW at slot \"" << pair->slot() << "\" is not of type Otw" << std::endl;
            }
        }
    }

   // Remove the old OTW interfaces
   if (otw != 0) {

      SPtr<Basic::PairStream> oldList( otw );
      otw = 0;

      // we are no longer the container for these old OTW interfaces
      for (Basic::List::Item* item = oldList->getFirstItem(); item != 0; item = item->getNext()) {
         Basic::Pair* pair = (Basic::Pair*)(item->getValue());
         Component* p = (Component*)( pair->object() );
         p->container(0);
      }
   }

   // Set the pointer to the list of OTW interfaces
   otw = newList;

   return true;
}
// Sets the actor/behavior list
bool MultiActorAgent::setSlotAgentList(Basic::PairStream* const msg)
{
    bool ok = false;
    if (msg != nullptr) {
       // First clear the old list
       clearAgentList();

       // Now scan the pair stream and put all Ntm objects into the table.
       Basic::List::Item* item = msg->getFirstItem();
       while (item != nullptr) {
          Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
          //std::cerr << "MultiActorAgent::setSlotagentList: slot: " << *pair->slot() << std::endl;
          Basic::Ubf::Behavior* b = dynamic_cast<Basic::Ubf::Behavior*>( pair->object() );
          if (b != nullptr) {
             // We have an  object, so put it in the table
             addAgent(pair->slot(), b);
          }
          item = item->getNext();
       }
       ok = true;
    }
    return ok;
}
Пример #7
0
bool Station::setSlotIoHandler(Basic::PairStream* const list)
{
    bool ok = true;

    // Remove the old list
    if (ioHandlers != 0) {
        // we are no longer the container for these handlers
        for (Basic::List::Item* item = ioHandlers->getFirstItem(); item != 0; item = item->getNext()) {
            Basic::Pair* pair = (Basic::Pair*)(item->getValue());
            Basic::Component* p = (Basic::Component*)( pair->object() );
            p->container(0);
        }
        ioHandlers = 0;
    }

    // Set our list pointer
    ioHandlers = list;

    // Make sure the new list is setup correctly
    if (ioHandlers != 0) {
        for (Basic::List::Item* item = ioHandlers->getFirstItem(); item != 0; item = item->getNext()) {
            Basic::Pair* pair = (Basic::Pair*)(item->getValue());
            Basic::IoHandler* p = dynamic_cast<Basic::IoHandler*>( pair->object() );
            if (p != 0) {
                // We are its container
                p->container(this);
            }
            else {
                // Not of the proper type
                std::cerr << "Player::setSlotIoHandler: Slot \"" << pair->slot() << "\" is not of type Basic::IoHandler" << std::endl;
                ok = false;
            }
        }
    }
    return ok;
}