1 /* |
|
2 * Copyright (c) 1999-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 package com.nokia.mj.impl.rt.legacy; |
|
21 |
|
22 public class MIDEventServer |
|
23 { |
|
24 private static final int MAX_USER_NAME=64; |
|
25 |
|
26 private final int iHandle; |
|
27 /** |
|
28 * Construct a named EPOC event server system. |
|
29 * <p> |
|
30 * The server and event threads manage EPOC event notification |
|
31 * and propogation of those events back to Java. |
|
32 * |
|
33 * The native server handle should be passed through to |
|
34 * native event sources to bind to this event server. |
|
35 * @see getHandle |
|
36 * @param aName The event server system to use |
|
37 */ |
|
38 public MIDEventServer(String aName) |
|
39 { |
|
40 super(); |
|
41 iHandle = openEventServer(aName, new DefaultFactory()); |
|
42 } |
|
43 |
|
44 protected MIDEventServer(String aName, MIDEventServerFactory aFactory) |
|
45 { |
|
46 super(); |
|
47 iHandle = openEventServer(aName, aFactory); |
|
48 } |
|
49 |
|
50 private int openEventServer(String aName, MIDEventServerFactory aFactory) |
|
51 { |
|
52 // |
|
53 if (aName.length()>MAX_USER_NAME) |
|
54 { |
|
55 throw new IllegalArgumentException(); |
|
56 } |
|
57 int server = aFactory.createServer(aName); |
|
58 NativeError.checkOOM(server); |
|
59 return server; |
|
60 } |
|
61 /** |
|
62 * Get the server handle for passing through to native |
|
63 * event sources. |
|
64 * @returns The handle of the native event server |
|
65 */ |
|
66 public int getHandle() |
|
67 { |
|
68 return iHandle; |
|
69 } |
|
70 |
|
71 public void shutdown() |
|
72 { |
|
73 _shutdown(iHandle); |
|
74 } |
|
75 |
|
76 private class DefaultFactory implements MIDEventServerFactory |
|
77 { |
|
78 DefaultFactory() |
|
79 { |
|
80 } |
|
81 public int createServer(String aName) |
|
82 { |
|
83 return _createServer(aName); |
|
84 } |
|
85 } |
|
86 |
|
87 /** |
|
88 * Native methods required to implement getServer() |
|
89 */ |
|
90 private native void _shutdown(int aHandle); |
|
91 private native int _createServer(String aName); |
|
92 }; |
|
93 |
|