summaryrefslogtreecommitdiff
path: root/NET/worlds/console/ActiveX.java
blob: 19b59e38e5699c4e1ddf2db49662a11073f73d78 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package NET.worlds.console;

import NET.worlds.core.IniFile;
import java.io.IOException;
import java.util.Vector;

public class ActiveX implements MainCallback, MainTerminalCallback {
   private static boolean disabled = IniFile.gamma().getIniInt("DISABLEACTIVEX", 0) != 0;
   private static ActiveX _instance;
   private static int _references;
   private static Vector<IUnknown> _referrers = new Vector<IUnknown>();
   private static int _serverLocks;
   private static int _activeComponents;
   private static int _debugLevel = IniFile.gamma().getIniInt("oledebug", 0);
   public int _shutdownCounter = 0;

   static {
      if (_debugLevel > 0) {
         System.out.println("OLE DEBUGGING LEVEL = " + _debugLevel);
      }
   }

   public static int getDebugLevel() {
      return _debugLevel;
   }

   public static ActiveX getInstance() {
      if (_instance == null) {
         _instance = new ActiveX();
      }

      return _instance;
   }

   private ActiveX() {
      Main.register(this);
   }

   @Override
   public void mainCallback() {
      this.winProc();
   }

   @Override
   public void terminalCallback() {
      assert this == _instance;

      if (_serverLocks <= 0 && _activeComponents <= 0) {
         synchronized (this) {
            assert _references == _referrers.size();

            while (_references > 0) {
               for (int i = _referrers.size() - 1; i >= 0; i--) {
                  IUnknown pUnk = _referrers.elementAt(i);

                  try {
                     pUnk.Release();
                  } catch (OLEInvalidObjectException var5) {
                     var5.printStackTrace(System.out);
                     System.out.println("ActiveX: misbehaved object detected: " + pUnk);
                     _referrers.removeElementAt(i);
                  }
               }

               if (_referrers.size() > 0) {
                  System.out.println("ActiveX: bad referrers found:");

                  for (int i = _referrers.size() - 1; i >= 0; i--) {
                     IUnknown pUnk = _referrers.elementAt(i);
                     System.out.println("\t" + pUnk);
                  }
               }
            }

            assert _references == 0;

            Main.unregister(this);
         }
      } else {
         this._shutdownCounter++;
         if (this._shutdownCounter == 10) {
            this._shutdownCounter = 0;
            System.out.println("Shutdown ignored: _serverLocks = " + _serverLocks + ", _activeComponents = " + _activeComponents);
            Exception e = new Exception();
            e.printStackTrace(System.out);
         }
      }
   }

   public static void init(IUnknown referrer) throws IOException {
      synchronized (getInstance()) {
         assert !_referrers.contains(referrer);

         if (_references == 0) {
            initActiveX();
         }

         _references++;
         _referrers.addElement(referrer);
         if ((_debugLevel & 1) > 0) {
            System.out.println("ActiveX.init() - refCnt = " + _references);
         }
      }
   }

   public static void uninit(IUnknown referrer) {
      synchronized (getInstance()) {
         assert _references > 0;

         assert _referrers.contains(referrer);

         _references--;
         if (_references == 0) {
            uninitActiveX();
         }

         _referrers.removeElement(referrer);
         if ((_debugLevel & 1) > 0) {
            System.out.println("ActiveX.uninit() - refCnt = " + _references);
         }
      }
   }

   public static synchronized void incServerLocks(int amt) {
      _serverLocks += amt;

      assert _serverLocks >= 0;
   }

   public static synchronized void incActiveComponents(int amt) {
      _activeComponents += amt;

      assert _activeComponents >= 0;
   }

   private static native void initActiveX() throws IOException;

   private static native void uninitActiveX();

   public static native int getClassFClsID(String var0, String var1) throws IOException;

   public static native int getClassFProgID(String var0, String var1) throws IOException;

   private static native int getClass(int var0, String var1) throws IOException;

   private native void winProc();
}