Commit 419c23cd81c0648c97ebe5cb99c030252bcf6a68
1 parent
6058ed37
Exists in
master
and in
5 other branches
Adding automatic unload of pw3270 sessions when the JNI is unloaded (Linux only for now).
Showing
3 changed files
with
39 additions
and
2 deletions
Show diff stats
src/classlib/session.cc
... | ... | @@ -46,14 +46,30 @@ |
46 | 46 | #define nullptr NULL |
47 | 47 | #endif // !c11 |
48 | 48 | |
49 | + | |
49 | 50 | /*--[ Implement ]--------------------------------------------------------------------------------------------------*/ |
50 | 51 | |
51 | - namespace PW3270_NAMESPACE | |
52 | - { | |
52 | + namespace PW3270_NAMESPACE { | |
53 | + | |
53 | 54 | session * session::first = nullptr; |
54 | 55 | session * session::last = nullptr; |
55 | 56 | session * (*session::factory)(const char *name) = nullptr; |
56 | 57 | |
58 | + void session::init() | |
59 | + { | |
60 | + trace("Loading %s objects",PACKAGE_NAME); | |
61 | + } | |
62 | + | |
63 | + void session::deinit() | |
64 | + { | |
65 | + trace("Unloading %s objects",PACKAGE_NAME); | |
66 | + while(first) | |
67 | + { | |
68 | + delete first; | |
69 | + } | |
70 | + | |
71 | + } | |
72 | + | |
57 | 73 | session::session() |
58 | 74 | { |
59 | 75 | ... | ... |
src/include/pw3270/class.h
... | ... | @@ -128,6 +128,10 @@ |
128 | 128 | |
129 | 129 | virtual ~session(); |
130 | 130 | |
131 | + // Internal methods, used to init/deinit control tables. | |
132 | + static void init(); | |
133 | + static void deinit(); | |
134 | + | |
131 | 135 | // Factory methods and settings |
132 | 136 | static session * start(const char *name = 0); |
133 | 137 | static session * create(const char *name = 0) throw (std::exception); | ... | ... |
src/java/main.cc
... | ... | @@ -32,6 +32,23 @@ |
32 | 32 | |
33 | 33 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
34 | 34 | |
35 | +#if defined(linux) | |
36 | + static void onLoad() __attribute__((constructor)); | |
37 | + static void onUnLoad() __attribute__((destructor)); | |
38 | +#endif // linux | |
39 | + | |
40 | + using namespace PW3270_NAMESPACE; | |
41 | + | |
42 | + static void onLoad() | |
43 | + { | |
44 | + session::init(); | |
45 | + } | |
46 | + | |
47 | + static void onUnLoad() | |
48 | + { | |
49 | + session::deinit(); | |
50 | + } | |
51 | + | |
35 | 52 | namespace PW3270_NAMESPACE { |
36 | 53 | |
37 | 54 | jfieldID java::getHandleField(JNIEnv *env, jobject obj) { | ... | ... |