/*!

\brief Dumps the current Resources to the observer.
\details The dmz::ResourcesObserver::update_resource() Mode parameter will be set to dmz::ResourcesDumped.

*/
void
dmz::ResourcesObserver::dump_current_resources () {

   if (__state.rc) {

      if (__state.mask & ResourcesPathMask) {

         HashTableStringIterator it;
         StringContainer *ptr (0);

         while (__state.rc->pathTable.get_next (it, ptr)) {

            update_resources_path (it.get_hash_key (), ResourcesDumped);
         }
      }

      if (__state.mask & ResourcesResourceMask) {

         HashTableStringIterator it;
         Config *ptr (0);

         while (__state.rc->rcTable.get_next (it, ptr)) {

            update_resource (it.get_hash_key (), ResourcesDumped);
         }
      }
   }
}
Beispiel #2
0
/*!

\brief Gets a list of all state names.
\param[out] list StringContainer used to return the list of state names.

*/
void
dmz::Definitions::get_state_names (StringContainer &list) const {

   if (_state.defs) {

      HashTableStringIterator it;

      Mask *ptr (0);

      while (_state.defs->maskTable.get_next (it, ptr)) {

         list.add (it.get_hash_key ());
      }
   }
}
/*!

\brief Serializes the Resources in a RuntimeContext and stores the result
in a Config object.
\ingroup Runtime
\details Format of the returned Config object:
\code
<runtime>
   <resource-map>
      <search name="String">
         <path value="String"/>
         <path value="String"/>
         <!-- ... -->
         <path value="String"/>
      </search>
      <!-- ... -->
      <search name="String">
         <!-- ... -->
      </search>
      <resource name="String" file="String"/>
      <resource name="String" file="String"/>
      <!-- ... -->
      <resource name="String" file="String"/>
   </resource-map>
</runtime>
\endcode

- \b resource-map.search.name String containing the name of the search paths. [Optional]
- \b resource-map.search.path.value String containing the name of the path to use in the search
- \b resource-map.resource.name String containing the name of the resource.
- \b resource-map.resource.file String containing the file name of the resource.

\param[in] context Pointer to the RuntimeContext to serialize.
\return Returns a Config object containing the serialized Resources in the
RuntimeContext.

*/
dmz::Config
dmz::runtime_resources_to_config (RuntimeContext *context) {

   Config result (RuntimeName);
   Config map ("resource-map");
   result.add_config (map);

   RuntimeContextResources *rc = (context ? context->get_resources_context () : 0);

   if (rc) {

      rc->ref ();

      HashTableStringIterator it;
      StringContainer *paths (0);

      while (rc->pathTable.get_next (it, paths)) {

         Config list ("search");

         const String Name = it.get_hash_key ();

         if (Name) { list.store_attribute ("name", Name); }

         StringContainerIterator scIt;
         String value;

         while (paths->get_next (scIt, value)) {

            Config data ("path");
            data.store_attribute ("value", value);
            list.add_config (data);
         }

         map.add_config (list);
      }

      it.reset ();

      Config *ptr (0);

      while (rc->rcTable.get_next (it, ptr)) { map.add_config (*ptr); }

      rc->unref ();
   }

   return result;
}
Beispiel #4
0
//! Assignment operator.
dmz::StringContainer &
dmz::StringContainer::operator= (const StringContainer &Container) {

   _state.table.clear ();

   HashTableStringIterator it;

   void *ptr = Container._state.table.get_next (it);

   while (ptr) {

      _state.table.store (it.get_hash_key (), (void *)this);
      ptr = Container._state.table.get_next (it);
   }

   return *this;
}
Beispiel #5
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;
}
/*!

\brief Activates dmz::ResourcesObserver::update_resource() callback.
\param[in] Mode Specifies if all currently defined resources should be dumped to observer
upon activation.
\param[in] TheMask A mask specifying which callbacks to activate.
\return Returns a mask of all callbacks that were activated.

*/
dmz::UInt32
dmz::ResourcesObserver::set_resources_observer_callback_mask (
      const ResourcesActivateModeEnum Mode,
      const UInt32 TheMask) {

   if (__state.rc) {

      const Boolean Dump = (Mode == ResourcesDumpAll);

      const Handle ObsHandle = __state.ObsHandle;

      if (ResourcesPathMask & TheMask) {

         if ((ResourcesPathMask & __state.mask) == 0) {

            if (__state.rc->pathObsTable.store (ObsHandle, this)) {

               __state.mask |= ResourcesPathMask;

               if (Dump) {

                  HashTableStringIterator it;
                  StringContainer *ptr (0);

                  while (__state.rc->pathTable.get_next (it, ptr)) {

                     update_resources_path (it.get_hash_key (), ResourcesCreated);
                  }
               }
            }
         }
      }
      else if (ResourcesPathMask & __state.mask) {

         __state.mask &= ~ResourcesPathMask;
         __state.rc->pathObsTable.remove (ObsHandle);
      }

      if (ResourcesResourceMask & TheMask) {

         if ((ResourcesResourceMask & __state.mask) == 0) {

            if (__state.rc->rcObsTable.store (ObsHandle, this)) {

               __state.mask |= ResourcesResourceMask;

               if (Dump) {

                  HashTableStringIterator it;
                  Config *ptr (0);

                  while (__state.rc->rcTable.get_next (it, ptr)) {

                     update_resource (it.get_hash_key (), ResourcesCreated);
                  }
               }
            }
         }
      }
      else if (ResourcesResourceMask & __state.mask) {

         __state.mask &= ~ResourcesResourceMask;
         __state.rc->rcObsTable.remove (ObsHandle);
      }
   }

   return __state.mask;
}
Beispiel #7
0
/*!

\brief Initialized the runtime types, state, and time.
\ingroup Runtime
\details Defined in dmzRuntimeInit.h. \n
An XML example for defining the various runtime types and time settings:
\code
<dmz>
<runtime>

   <time>
      <factor value="1.0"/>
      <frequency value="60"/>
   </time>

   <!-- State definition -->
   <state name="State Name"/>

   <!-- dmz::ObjectType definition -->
   <object-type name="Object Name" parent="Parent Name">
      <!-- Object data -->
   </object-type>

   <!-- dmz::EventType definition -->
   <event-type name="Event Name" parent="Parent Name">
      <!-- Event data -->
   </event-type>

   <!-- dmz::Message definition -->
   <message name="Message Name" parent="Parent Name"/>

   <!-- dmz::Resources definition -->
   <resource-map>
      <!-- Search Path Group -->
      <search name="Search Path Name">
         <path value="Search Path 1"/>
         <path value="Search Path 2"/>
         ...
         <path value="Search Path N"/>
      </search>
      <!-- Resource List -->
      <resource name="Resource Name 1" file="Resource File" path="Search Name"/>
      <resource name="Resource Name 2" file="Resource File" path="Search Name"/>
      ...
      <resource name="Resource Name N" file="Resource File" path="Search Name"/>
   </resource-map>
</runtime>
</dmz>
\endcode
\param[in] Init Config containing runtime initialization data.
\param[in] context Pointer to runtime context.
\param[in] log Pointer to Log to use for log messages.
\sa dmz::ObjectType \n dmz::EventType \n dmz::Message \n dmz::Time

*/
void
dmz::runtime_init (const Config &Init, RuntimeContext *context, Log *log) {

   Config econfig;
   Config oconfig;
   Config sconfig;
   Config mconfig;
   Config tconfig;
   Config rconfig;

   Init.lookup_all_config ("event-type", econfig);
   Init.lookup_all_config ("object-type", oconfig);
   Init.lookup_all_config ("state", sconfig);
   Init.lookup_all_config ("message", mconfig);
   Init.lookup_all_config_merged ("time", tconfig);
   Init.lookup_all_config_merged ("resource-map", rconfig);

   if (context) {

      if (econfig || oconfig || sconfig) {

         RuntimeContextDefinitions *defs = context->get_definitions_context ();

         if (defs) {

            defs->ref ();
            if (econfig) { local_init_event_type (econfig, *defs, context, log); }
            else if (log) { log->debug << "Event type config not found" << endl; }
            if (oconfig) { local_init_object_type (oconfig, *defs, context, log); }
            else if (log) { log->debug << "Object type config not found" << endl; }
            if (sconfig) { local_init_state (sconfig, *defs, log); }
            else if (log) { log->debug << "State config not found" << endl; }

            if (defs->handleObsTable.get_count () > 0) {

               HashTableHandleIterator it;
               String *ptr (0);

               while (defs->namedHandleNameTable.get_next (it, ptr)) {

                  defs->define_named_handle (it.get_hash_key (), *ptr);
               }
            }

            if (defs->maskObsTable.get_count () > 0) {

               HashTableStringIterator it;
               Mask *ptr (0);

               while (defs->maskTable.get_next (it, ptr)) {

                  defs->define_state (*ptr, it.get_hash_key ());
               }
            }

            if (defs->objectObsTable.get_count () > 0) {

               HashTableHandleIterator it;
               ObjectType *ptr (0);

               while (defs->objectHandleTable.get_next (it, ptr)) {

                  defs->define_object_type (*ptr);
               }
            }

            if (defs->eventObsTable.get_count () > 0) {

               HashTableHandleIterator it;
               EventType *ptr (0);

               while (defs->eventHandleTable.get_next (it, ptr)) {

                  defs->define_event_type (*ptr);
               }
            }

            defs->unref (); defs = 0;
         }
      }

      if (mconfig) { local_init_message (mconfig, context, log); }
      else if (log) { log->debug << "Message type config not found" << endl; }

      if (tconfig) { local_init_time (tconfig, context, log); }
      else if (log) { log->debug << "Runtime time data not found" << endl; }

      if (rconfig) { local_init_resources (rconfig, context, log); }
      else if (log) { log->debug << "Runtime resource data not found" << endl; }
   }
}