process.cpp

Engine/source/core/util/journal/process.cpp

More...

Public Variables

Detailed Description

Public Variables

Process * _theOneProcess 

the one instance of the Process class

 MODULE_END 
 MODULE_INIT 
 MODULE_SHUTDOWN 
  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "core/util/journal/process.h"
 25#include "core/util/journal/journal.h"
 26#include "core/module.h"
 27
 28
 29MODULE_BEGIN( Process )
 30
 31   MODULE_INIT
 32   {
 33      Process::init();
 34   }
 35   
 36   MODULE_SHUTDOWN
 37   {
 38      Process::shutdown();
 39   }
 40
 41MODULE_END;
 42
 43static Process* _theOneProcess = NULL; ///< the one instance of the Process class
 44
 45//-----------------------------------------------------------------------------
 46
 47void Process::requestShutdown(S32 status)
 48{
 49   Process::get()._RequestShutdown = true;
 50   Process::get()._ReturnStatus = status;
 51}
 52
 53S32 Process::getReturnStatus()
 54{
 55   return Process::get()._ReturnStatus;
 56}
 57
 58//-----------------------------------------------------------------------------
 59
 60Process::Process()
 61:  _RequestShutdown( false ), _ReturnStatus( 0 )
 62{
 63}
 64
 65Process &Process::get()
 66{
 67   struct Cleanup
 68   {
 69      ~<a href="/coding/file/platformx86unix_8h/#platformx86unix_8h_1a4a381e2cc1b52cefc693f48915947f80">Cleanup</a>()
 70      {
 71         if( _theOneProcess )
 72            delete _theOneProcess;
 73      }
 74   };
 75   static Cleanup cleanup;
 76
 77   // NOTE that this function is not thread-safe
 78   //    To make it thread safe, use the double-checked locking mechanism for singleton objects
 79
 80   if ( !_theOneProcess )
 81      _theOneProcess = new Process;
 82
 83   return *_theOneProcess;
 84}
 85
 86bool Process::init()
 87{
 88   return Process::get()._signalInit.trigger();
 89}
 90
 91void  Process::handleCommandLine(S32 argc, const char **argv)
 92{
 93   Process::get()._signalCommandLine.trigger(argc, argv);
 94}
 95
 96bool  Process::processEvents()
 97{
 98   // Process all the devices. We need to call these even during journal
 99   // playback to ensure that the OS event queues are serviced.
100   Process::get()._signalProcess.trigger();
101
102   if (!Process::get()._RequestShutdown) 
103   {
104      if (Journal::IsPlaying())
105         return Journal::PlayNext();
106      return true;
107   }
108
109   // Reset the Quit flag so the function can be called again.
110   Process::get()._RequestShutdown = false;
111   return false;
112}
113
114bool  Process::shutdown()
115{
116   return Process::get()._signalShutdown.trigger();
117}
118