Pol  Revision:cb584c9
uoexec.cpp
Go to the documentation of this file.
1 #include "uoexec.h"
2 
3 #include <stddef.h>
4 
5 #include "../bscript/executor.h"
6 #include "../clib/logfacility.h"
7 #include "../plib/systemstate.h"
8 #include "globals/settings.h"
9 #include "module/osmod.h"
10 #include "polcfg.h"
11 #include "polclock.h"
12 
13 namespace Pol
14 {
15 namespace Core
16 {
18  : Executor(),
19  os_module( nullptr ),
20  instr_cycles( 0 ),
21  sleep_cycles( 0 ),
22  start_time( poltime() ),
23  warn_runaway_on_cycle( Plib::systemstate.config.runaway_script_threshold ),
24  runaway_cycles( 0 ),
25  eventmask( 0 ),
26  area_size( 0 ),
27  speech_size( 1 ),
28  can_access_offline_mobiles( false ),
29  auxsvc_assume_string( false ),
30  pParent( nullptr ),
31  pChild( nullptr )
32 {
33  weakptr.set( this );
34  os_module = new Module::OSExecutorModule( *this );
36 }
37 
39 {
40  // note, the os_module isn't deleted here because
41  // the Executor deletes its ExecutorModules.
43  {
44  int elapsed = static_cast<int>(
45  poltime() - start_time ); // Doh! A script can't run more than 68 years, for this to work.
46  POLLOG_ERROR.Format( "Script {}: {} instr cycles, {} sleep cycles, {} seconds\n" )
48  }
49 
50  pParent = nullptr;
51  pChild = nullptr;
52 }
53 
55 {
56  // Run to completion scripts can't be suspended
57  if ( running_to_completion() )
58  return false;
59 
60  os_module->suspend();
61  return true;
62 }
63 
65 {
66  os_module->revive();
67  return true;
68 }
69 
70 std::string UOExecutor::state()
71 {
72  if ( halt() )
73  return "Debugging";
74  else if ( os_module->blocked() )
75  return "Sleeping";
76  else
77  return "Running";
78 }
79 
81 {
82  return sizeof( UOExecutor ) + base::sizeEstimate();
83 }
84 }
85 }
SystemState systemstate
Definition: systemstate.cpp:12
bool profile_scripts
Definition: watch.h:15
void addModule(ExecutorModule *module)
Definition: executor.cpp:3032
std::string elapsed(clock_t start, clock_t end)
Definition: uimport.cpp:357
#define POLLOG_ERROR
Definition: logfacility.h:207
virtual ~UOExecutor()
Definition: uoexec.cpp:38
virtual size_t sizeEstimate() const POL_OVERRIDE
Definition: uoexec.cpp:80
UOExecutor * pChild
Definition: uoexec.h:64
weak_ptr_owner< UOExecutor > weakptr
Definition: uoexec.h:62
time_t poltime()
Definition: polclock.cpp:102
SettingsManager settingsManager
Definition: settings.cpp:14
UOExecutor * pParent
Definition: uoexec.h:64
std::string state()
Definition: uoexec.cpp:70
bool running_to_completion() const
Definition: executor.h:467
const std::string & scriptname() const
Definition: executor.h:413
virtual size_t sizeEstimate() const
Definition: executor.cpp:3099
Definition: berror.cpp:12
bool halt() const
Definition: executor.h:452
Module::OSExecutorModule * os_module
Definition: uoexec.h:37
bool blocked() const
Definition: osmod.h:158