View Javadoc

1   package com.tapina.robe.swi;
2   
3   import com.tapina.robe.runtime.Environment;
4   
5   import java.lang.reflect.Method;
6   
7   /***
8    * Java implementation of Peter Naulls' module used by UnixLib programs.
9    * From: http://www.drobe.co.uk/riscos/artifact1253.html
10   * What is SharedUnixLibary?
11   * I want to say very little about this, since it's been a huge cause of confusion for no good reason. Its singular,
12   * and only purpose, is to catch a callback that RISC OS makes when an application quits. RISC OS helpfully insists on
13   * calling this (for a variety of reasons) when the listening application might be paged out, thereby jumping to random
14   * code and quickly causing your computer to freeze or crash some unrelated program. This code is therefore in a module
15   * and only passes the message onto Unixlib when it is safe to do so. The issue has been fixed in Select/Adjust, but
16   * Unixlib has not been modified to avoid this on machines running those versions of RISC OS.
17   * NB: This is in no way similar in operation to SharedCLibrary.
18   */
19  public class SharedUnixLibrary extends SWIHandler {
20      private static SharedUnixLibrary ourInstance;
21  
22      public synchronized static SharedUnixLibrary getInstance() {
23          if (ourInstance == null) {
24              ourInstance = new SharedUnixLibrary();
25          }
26          return ourInstance;
27      }
28  
29      private SharedUnixLibrary() {
30      }
31  
32      public static int getBase() {
33          return 0x55c80;
34      }
35  
36      private static final String[] methodNames = new String[]{
37          "RegisterUpCall", "DeRegisterUpCall", "SetValueCount", "", "", "", "", "", // 0x55c80
38          "", "", "", "", "", "", "", "", // 0x55c88
39          "", "", "", "", "", "", "", "", // 0x55c90
40          "", "", "", "", "", "", "", "", // 0x55c98
41          "", "", "", "", "", "", "", "", // 0x55ca0
42          "", "", "", "", "", "", "", "", // 0x55ca8
43          "", "", "", "", "", "", "", "", // 0x55cb0
44          "", "", "", "", "", "", "", ""  // 0x55cb8
45      };
46  
47      public static Method getMethod(Integer offset) throws NoSuchMethodException {
48          return getMethod(methodNames[offset.intValue()]);
49      }
50  
51      private static final Method getMethod(String name) throws NoSuchMethodException {
52          return SharedUnixLibrary.class.getMethod(name, METHOD_PARAMETERS);
53      }
54  
55      public void RegisterUpCall(Environment env) {
56          log.warning("SharedUnixLibrary.RegisterUpCall ignored");
57      }
58  
59      public void DeRegisterUpCall(Environment env) {
60          log.warning("SharedUnixLibrary.DeRegisterUpCall ignored");
61      }
62  
63      public void SetValueCount(Environment env) {
64          log.warning("SharedUnixLibrary.SetValueCount ignored");
65      }
66  
67  }