Exemplo n.º 1
0
dmz::Mask
dmz::ArchivePluginObject::_filter_state (
      const Handle AttrHandle,
      const Mask &Value,
      const UInt32 Mode) {

   Mask result (Value);

   if (_currentFilterList) {

      FilterStruct *filter = _currentFilterList->list;

      while (filter) {

         if (filter->mode & Mode) {

            Mask *filterMask (filter->stateTable.lookup (AttrHandle));

            if (filterMask) { result.unset (*filterMask); }
         }

         filter = filter->next;
      }
   }

   return result;
}
Exemplo n.º 2
0
    Status Resolver::resolveRelativePathsStartingAddresses(
            const vector<Address>&  relativePathAddresses,
            Mask&                   mask,
            vector<BrowsePath>&     results,
            vector<Status>&         statuses)
    {
        // declare the return status
        Status ret(statuscodes::Good);

        // declare the number of relative paths
        size_t noOfRelativePaths = relativePathAddresses.size();

        // resize the output parameters
        results.resize(noOfRelativePaths);
        statuses.resize(noOfRelativePaths);

        // fill a vector containing all starting addresses
        vector<Address> startingAddresses;
        for (size_t i = 0; i < noOfRelativePaths && ret.isGood(); i++)
        {
            if (mask.isSet(i))
                startingAddresses.push_back(*(relativePathAddresses[i].getStartingAddress()));
        }

        // resolve them (recursively!)
        vector<ExpandedNodeId>  startingAddressesResults;
        vector<Status>          startingAddressesStatuses;
        ret = resolve(startingAddresses, startingAddressesResults, startingAddressesStatuses);

        // update the results
        for (size_t i = 0, j = 0; i < noOfRelativePaths && ret.isGood(); i++)
        {
            if (mask.isSet(i))
            {
                // update the results
                results[i].startingExpandedNodeId = startingAddressesResults[j];
                results[i].relativePath           = relativePathAddresses[i].getRelativePath();

                // update the statuses
                statuses[i] = startingAddressesStatuses[j];

                // update the mask (only resolved starting addresses should be processed further!)
                if (statuses[i].isNotGood())
                    mask.unset(i);

                // increment the index of the startingAddressesResults
                j++;
            }
        }

        return ret;
    }
Exemplo n.º 3
0
// TimeSlice Interface
void
dmz::EntityPluginDeadTimer::update_time_slice (const Float64 TimeDelta) {

   ObjectModule *objMod (get_object_module ());

   if (objMod && _hil) {

      Mask state;
      objMod->lookup_state (_hil, _defaultHandle, state);
      state.unset (_deadState);
      objMod->store_state (_hil, _defaultHandle, state);
   }
}
Exemplo n.º 4
0
/*!

\brief Gets state names.
\param[in] State Mask containing states to be named.
\param[out] name String to store found state names.
\return Returns dmz::True if all the states stored in \a State have names.
\note This function will find the names for as many states as possible. If the \a State
mask contains more than one state, the names are separated by the "|" character
(a.k.a. bitwise or operator).

*/
dmz::Boolean
dmz::Definitions::lookup_state_name (const Mask &State, String &name) const {

   Boolean result (False);

   Mask maskCopy (State);

   if (_state.defs) {

      name.flush ();

      HashTableStringIterator it;

      Mask *ptr = _state.defs->maskTable.get_first (it);

      while (ptr) {

         if (State & *ptr) {

            if (!name) { name = it.get_hash_key (); }
            else { name << " | " << it.get_hash_key (); }

            maskCopy.unset (*ptr);
         }

         ptr = _state.defs->maskTable.get_next (it);
      }

      if (!maskCopy) { result = True; }
      else if (_state.log) {

         _state.log->error << "Unidentified state bits in: " << name << endl;
            // << ", unknown bits: " << maskCopy << endl;
      }
   }

   return result;
}
// TimeSlice Interface
void
dmz::EntityPluginGroundSimple::update_time_slice (const Float64 TimeDelta) {

   ObjectModule *objMod (get_object_module ());

   if ((_active > 0) && objMod && _hil && _defaultHandle) {

      Vector pos, vel;
      Matrix ori;
      Mask state;

      objMod->lookup_position (_hil, _defaultHandle, pos);
      objMod->lookup_velocity (_hil, _defaultHandle, vel);
      objMod->lookup_orientation (_hil, _defaultHandle, ori);
      objMod->lookup_state (_hil, _defaultHandle, state);

      const Vector OldPos (pos);
      const Matrix OldOri (ori);

      const Vector Up (0.0, 1.0, 0.0);

      Vector point (pos), normal (Up);

      Boolean airborn (False);

      if (_find_point (pos, ori, point, normal)) {

         Float64 Diff (pos.get_y () - point.get_y ());

         Float64 Drop (EarthGravity64 * TimeDelta * TimeDelta);

         if (Diff > Drop) { airborn = True; }
      }

      if (airborn) { state |= _airBornState; }
      else { state.unset (_airBornState); }

      if (_eventMod && _wasAirborn && !airborn) {

         _eventMod->create_collision_event (_hil, 0);
      }

      _wasAirborn = airborn;

      Float64 heading (0.0);

      _move_entity (TimeDelta, airborn, pos, ori, vel, heading);

      _validate_move (TimeDelta, airborn, OldPos, pos, ori, vel, heading);

      if (_find_point (pos, ori, point, normal)) {

         if ((point.get_y () > pos.get_y ()) || (point - pos).is_zero (0.01)) {

            pos = point;

            Matrix hm (Up, heading);
            Matrix nmat (Up, normal);

            ori = nmat * hm;

            get_orthogonal_component (normal, vel, vel);
         }
      }

      objMod->store_position (_hil, _defaultHandle, pos);
      objMod->store_velocity (_hil, _defaultHandle, vel);
      objMod->store_orientation (_hil, _defaultHandle, ori);
      objMod->store_state (_hil, _defaultHandle, state);

      Float64 target (_move.throttle + 0.3);

      if (_move.turboModifier > 0.0) { target += 0.3; }

      if (airborn) { target = (1.5 * _move.throttle) + 0.3; }

      Float64 current (1.0);

      objMod->lookup_scalar (_hil, _throttleHandle, current);

      if (current > target) {

         current -= 0.6 * TimeDelta;

         if (current < target) { current = target; }
      }
      else if (current < target) {

         current += 0.4 * TimeDelta;

         if (current > target) { current = target; }
      }

      if (_isDead) { current = 0.0; }

      objMod->store_scalar (_hil, _throttleHandle, current);

      const Float64 Time (_time.get_frame_time ());

      if ((_move.turboModifier > 0.0) && (Time > _move.turboEndTime)) {

         _move.turboModifier = 0.0;
         _move.turboRefillTime = Time + _move.turboRefillDuration;
      }
   }
}
Exemplo n.º 6
0
void
dmz::InputModuleBasic::release_input_observer (
      const Handle Channel,
      const Mask EventMask,
      InputObserver &obs) {

   if (_inEvent) { _que_event (new ReleaseObserverStruct (Channel, EventMask, obs)); } 
   else {

      _inEvent = True;

      ChannelStruct *cs (_channelTable.lookup (Channel));
      const Handle ObsHandle (obs.get_input_observer_handle ());
      ObsStruct *os (_obsTable.lookup (ObsHandle));

      if (cs && os) {

         Mask *obsMask (os->table.lookup (Channel));

         if (obsMask) {

            Mask updateMask;

            if (EventMask & LocalStateMask) {

               if (cs->stateTable.remove (ObsHandle)) { obsMask->unset (LocalStateMask); }
            }

            if (EventMask & LocalAxisMask) {

               if (cs->axisTable.remove (ObsHandle)) {

                  obsMask->unset (LocalAxisMask);
                  updateMask |= LocalAxisMask;
               }
            }

            if (EventMask & LocalButtonMask) {

               if (cs->buttonTable.remove (ObsHandle)) {

                  obsMask->unset (LocalButtonMask);
                  updateMask |= LocalButtonMask;
               }
            }

            if (EventMask & LocalSwitchMask) {

               if (cs->switchTable.remove (ObsHandle)) {

                  obsMask->unset (LocalSwitchMask);
                  updateMask |= LocalSwitchMask;
               }
            }

            if (EventMask & LocalKeyMask) {

               if (cs->keyTable.remove (ObsHandle)) {

                  obsMask->unset (LocalKeyMask);
                  updateMask |= LocalKeyMask;
               }
            }

            if (EventMask & LocalMouseMask) {

               if (cs->mouseTable.remove (ObsHandle)) {

                  obsMask->unset (LocalMouseMask);
                  updateMask |= LocalMouseMask;
               }
            }

            if (EventMask & LocalDataMask) {

               if (cs->dataTable.remove (ObsHandle)) {

                  obsMask->unset (LocalDataMask);
                  updateMask |= LocalDataMask;
               }
            }

            if (cs->active && updateMask.is_set ()) {

               _decrement_active_count (cs->ChannelHandle, updateMask, *os);
            }

            if (!obsMask->is_set ()) {

               cs->activeTable.remove (os->ObsHandle);

               if (os->table.remove (Channel)) { delete obsMask; obsMask = 0; }

               if (os->table.get_count () == 0) {

                  if (_obsTable.remove (ObsHandle)) { delete os; os = 0; }
               }
            }
         }
      }

      _inEvent = False;

      _do_qued_events ();
   }
}
Exemplo n.º 7
0
    void Resolver::processBrowsePathsResolutionResultTarget(
            const TranslateBrowsePathsToNodeIdsResultTarget&    target,
            size_t                                              rank,
            vector<BrowsePath>&                                 browsePaths,
            Mask&                                               mask,
            vector<ExpandedNodeId>&                             results,
            vector<Status>&                                     statuses)
    {
        // check the target status
        if (target.status.isBad())
        {
            logger_->error("Target %d could not be resolved: %s",
                           rank, target.status.toString().c_str());
            statuses[rank] = target.status;
            // we're finished with this target (unfortunately, because it failed),
            // so unset the mask item
            mask.unset(rank);
        }
        else
        {
            // check if only one ExpandedNodeId was found
            // (if not, we cannot "resolve" the target)
            if (target.expandedNodeIds.size() == 0)
            {
                // no matches, which would be unexpected since the status reported
                // by the server was not Bad
                statuses[rank] = UnexpectedError(
                                         "Server reported a Good translation result but no"
                                         "results were given");

                logger_->error(statuses[rank]);

                // we're finished with this target, so unset the mask item
                mask.unset(rank);
            }
            else if (target.expandedNodeIds.size() == 1)
            {
                // one match was found for the browse path, just as we expected!

                // we still need to check if the browse path was fully resolved:
                if (target.status.isGood())
                {
                    // update the result and status
                    results[rank]  = target.expandedNodeIds[0];
                    statuses[rank] = statuses[0];

                    logger_->debug("Target %d was successfully resolved to:", rank);
                    logger_->debug(results[rank].toString());

                    // we're finished with this target, so unset the mask item
                    mask.unset(rank);
                }
                else if (target.opcUaStatusCode == OpcUa_UncertainReferenceOutOfServer)
                {
                    logger_->debug("Target %d could not be fully resolved, there is an "
                                   "out-of-server reference", rank);

                    // declare the remaining path index
                    uint32_t remainingIndex = target.remainingPathIndexes[0];
                    uint32_t noOfElements   = browsePaths[rank].relativePath.size();
                    uint32_t maxIndex       = noOfElements - 1;

                    logger_->debug("Remaining index: %d (max index: %d)", remainingIndex, maxIndex);

                    if (remainingIndex == 0 || remainingIndex >= maxIndex)
                    {
                        statuses[rank] = UnexpectedError(
                                uaf::format(
                                "Unexpected translation result returned by the server (StatusCode="
                                "UncertainReferenceOutOfServer, RemainingPathIndex=%d), while "
                                "the number of BrowsePath elements is %d",
                                remainingIndex, noOfElements));

                        logger_->error(statuses[rank]);

                        // we're finished with this target, so unset the mask item
                        mask.unset(rank);
                    }
                    else
                    {
                        // copy the remaining elements to a new vector
                        vector<RelativePathElement> newElements;
                        for (uint32_t i = remainingIndex; i < maxIndex; i++)
                            newElements.push_back(browsePaths[rank].relativePath[i]);

                        // set the new browse path based on the just created elements
                        browsePaths[rank] = BrowsePath(target.expandedNodeIds[0], newElements);

                        logger_->debug("New browse path: %s", browsePaths[rank].toString().c_str());

                        // we're not finished with this target, so leave the mask item 'set'
                    }
                }
                else
                {
                    statuses[rank] = UnexpectedError(
                        uaf::format(
                            "Unexpected translation result (status reported by server: %s)",
                            target.status.toString().c_str()));

                    logger_->error(statuses[rank]);

                    // we're finished with this target, so unset the mask item
                    mask.unset(rank);
                }
            }
            else
            {
                // we received multiple matches for a single browse path!
                // This may be a valid result for a TranslateBrowsePathsToNodeIds service
                // invocation, but not in this case since we're trying to resolve an address.
                statuses[rank] = MultipleTranslationResultsError();

                logger_->error(statuses[rank].toString());

                // we're finished with this target, so unset the mask item
                mask.unset(rank);
            }
        }
    }