OSDN Git Service

update on the implementation of OnBoot event
authorShyouzou Sugitani <shy@users.sourceforge.jp>
Wed, 2 Jan 2013 14:22:44 +0000 (23:22 +0900)
committerShyouzou Sugitani <shy@users.sourceforge.jp>
Wed, 2 Jan 2013 14:22:44 +0000 (23:22 +0900)
ChangeLog
lib/ninix/sakura.py
lib/ninix_main.py

index 598ce34..8f0fde2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Wed January 2 2013   Shyouzou Sugitani <shy@users.sourceforge.jp>
+       * 異常終了後の起動でOnBootイベントのReference6, 7を送信するようにした.
+         ~/.ninix/.lock ファイルにタイマ割り込みを処理中のゴースト名を
+         書き込み, それが残っているかどうかを見ている. 正常終了時には
+         このゴースト名は消去される.
+         ゴーストを複数起動しても機能するが, 不正確な場合がある.
+         (SERIKO, SAORI, 猫どりふ等のタイマ割り込みが別にあるため,
+          そちらで落ちた場合はこの情報はあてにならない.)
+
 Sun December 9 2012   Shyouzou Sugitani <shy@users.sourceforge.jp>
        * バージョン4.99.7リリース.
 
index 0a4a087..0d1706e 100644 (file)
@@ -660,7 +660,8 @@ class Sakura:
 
     ###   CALLBACK   ###
     def notify_start(self, init, vanished, ghost_changed,
-                     name, prev_name, prev_shell, path, last_script):
+                     name, prev_name, prev_shell, path, last_script,
+                     abend=None):
         if self.__temp_mode:
             default = None
         else:
@@ -670,9 +671,21 @@ class Sakura:
                 if not self.notify_event('OnFirstBoot', self.vanished_count,
                                          None, None, None, None, None, None,
                                          self.surface.name):
-                    self.notify_event('OnBoot', self.surface.name, default=default)
+                    if abend is not None:
+                        self.notify_event('OnBoot', self.surface.name,
+                                          None, None, None, None, None,
+                                          'halt', abend, default=default)
+                    else:
+                        self.notify_event('OnBoot', self.surface.name,
+                                          default=default)
             else:
-                self.notify_event('OnBoot', self.surface.name, default=default)
+                if abend is not None:
+                    self.notify_event('OnBoot', self.surface.name,
+                                      None, None, None, None, None,
+                                      'halt', abend, default=default)
+                else:
+                    self.notify_event('OnBoot', self.surface.name,
+                                      default=default)
             left, top, scrn_w, scrn_h = ninix.pix.get_workarea()
             self.notify_event('OnDisplayChange',
                               Gdk.Visual.get_best_depth(),
@@ -689,7 +702,12 @@ class Sakura:
                                    prev_name, None, None, None, None,
                                    pref_shell):
                 return
-            self.notify_event('OnBoot', self.surface.name, default=default)
+            if abend is not None:
+                self.notify_event('OnBoot', self.surface.name,
+                                  None, None, None, None, None, None,
+                                  'halt', abend, default=default)
+            else:
+                self.notify_event('OnBoot', self.surface.name, default=default)
         elif ghost_changed:
             if self.ghost_time == 0:
                 if self.notify_event('OnFirstBoot', self.vanished_count,
@@ -700,7 +718,12 @@ class Sakura:
                                    prev_name, None, None, None, None,
                                    prev_shell):
                 return
-            self.notify_event('OnBoot', self.surface.name, default=default)
+            if abend is not None:
+                self.notify_event('OnBoot', self.surface.name,
+                                  None, None, None, None, None,
+                                  'halt', abend, default=default)
+            else:
+                self.notify_event('OnBoot', self.surface.name, default=default)
         else:
             pass ## FIXME
 
@@ -1170,7 +1193,7 @@ class Sakura:
             ##logging.debug('surface_life = {0:d}'.format(self.__surface_life))
 
     def start(self, key, init, temp, vanished, ghost_changed,
-              prev_self_name, prev_name, prev_shell, last_script):
+              prev_self_name, prev_name, prev_shell, last_script, abend):
         if self.is_running():
             if temp:
                 self.enter_temp_mode()
@@ -1180,7 +1203,8 @@ class Sakura:
                     self.load_shiori()
                     self.notify_start(
                         init, vanished, ghost_changed,
-                        prev_self_name, prev_name, prev_shell, '', last_script)
+                        prev_self_name, prev_name, prev_shell,
+                        '', last_script, abend)
             return
         self.ghost_time = 0
         self.vanished_count = 0
@@ -1222,7 +1246,7 @@ class Sakura:
         self.start_time = time.time()
         self.notify_start(
             init, vanished, ghost_changed,
-            name, prev_name, prev_shell, surface_dir, last_script)
+            name, prev_name, prev_shell, surface_dir, last_script, abend)
         GLib.timeout_add(10, self.do_idle_tasks) # 10[ms]
 
     def restart(self):
@@ -1373,6 +1397,7 @@ class Sakura:
     def do_idle_tasks(self):
         if not self.__running:
             return False
+        self.request_parent('NOTIFY', 'update_working', self.get_name())
         if self.__temp_mode:
             self.process_script()
             if not self.busy() and \
index 684ab5c..ffa295b 100644 (file)
@@ -137,17 +137,26 @@ def main():
             os.makedirs(home_dir)
         except:
             raise SystemExit('Cannot create Home directory (abort)\n')
+    lockfile_path = os.path.join(ninix.home.get_ninix_home(), b'.lock')
+    if os.path.exists(lockfile_path):
+        with open(lockfile_path, 'r') as f:
+            abend = f.readline()
+        if not abend:
+            abend = None
+    else:
+        abend = None
     # aquire Inter Process Mutex (not Global Mutex)
-    with open(os.path.join(ninix.home.get_ninix_home(), b'.lock'), 'w') as f:
+    with open(lockfile_path, 'w') as f:
         try:
             ninix.lock.lockfile(f)
         except:
             raise SystemExit('ninix-aya is already running')
         # start
         logging.info('loading...')
-        app = Application(sstp_port)
+        app = Application(f, sstp_port)
         logging.info('done.')
-        app.run()
+        app.run(abend)
+        f.truncate(0)
         try:
             ninix.lock.unlockfile(f)
         except:
@@ -521,7 +530,9 @@ class Ghost(Holon):
 
 class Application:
 
-    def __init__(self, sstp_port=[9801, 11000]):
+    def __init__(self, lockfile, sstp_port=[9801, 11000]):
+        self.lockfile = lockfile
+        self.abend = None
         self.loaded = False
         self.confirmed = False
         self.console = Console(self)
@@ -831,7 +842,7 @@ class Application:
         ##for i, name in enumerate(self.get_ghost_names()):
         ##    logging.info(
         ##        'GHOST({0:d}): {1}'.format(i, name))
-        self.start_sakura(self.current_sakura, init=1)
+        self.start_sakura(self.current_sakura, init=1, abend=self.abend)
 
     def find_ghost_by_dir(self, directory):
         return directory if directory in self.ghosts else None
@@ -876,7 +887,8 @@ class Application:
     def exit_handler(self, sig_no, frame=None):
         self.close_all_ghosts(reason='shutdown')
 
-    def run(self):
+    def run(self, abend):
+        self.abend = abend
         if os.name == "nt":
             # The SIGTERM signal is not generated under Windows NT.
             import win32api
@@ -1011,7 +1023,8 @@ class Application:
         self.set_menu_sensitive(sakura.key, True)
         self.close_ghost(sakura)
 
-    def start_sakura(self, key, prev=None, vanished=0, init=0, temp=0):
+    def start_sakura(self, key, prev=None, vanished=0, init=0, temp=0,
+                     abend=None):
         sakura = self.ghosts[key].instance
         assert sakura is not None
         if prev is not None:
@@ -1037,9 +1050,15 @@ class Application:
             last_script = None
         sakura.notify_preference_changed()
         sakura.start(key, init, temp, vanished, ghost_changed,
-                     self_name, name, shell, last_script)
+                     self_name, name, shell, last_script, abend)
         self.set_menu_sensitive(key, False)
 
+    def update_working(self, ghost_name):
+        self.lockfile.truncate(0)
+        self.lockfile.seek(0)
+        self.lockfile.write(ghost_name)
+        self.lockfile.flush()        
+
     def notify_preference_changed(self):
         for sakura in self.get_working_ghost():
             sakura.notify_preference_changed()