Source Code Cross Referenced for VoidPointer.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » awt » nativebridge » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.awt.nativebridge 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Sergey V. Kuksenko
019:         * @version $Revision$
020:         */package org.apache.harmony.awt.nativebridge;
021:
022:        /**
023:         * This class represents pointer to memory for working with native functions.
024:         * It is an analogue of <it>void*</it> C type. Every pointed object can be direct
025:         * native object or Java object. In both cases NativeBridge provides correct
026:         * passing addresses to native functions, native address is passed as is, Java
027:         * object will be implicitly locked and address of lock will be passed to native.
028:         * NULL pointer can't be wrapped by this object, NULL is represents by Java
029:         * null value.
030:         * @see org.apache.harmony.misc.accessors.MemoryAccessor
031:         * @see org.apache.harmony.misc.accessors.ArrayAccessor
032:         */
033:        public abstract class VoidPointer {
034:
035:            public ByteBase byteBase;
036:            boolean explicitlyLocked = false;
037:
038:            VoidPointer(int size, boolean direct) {
039:                byteBase = new ByteBase(size, direct);
040:            }
041:
042:            VoidPointer(byte[] arr, int offset, int size) {
043:                byteBase = new ByteBase(arr, offset, size);
044:            }
045:
046:            VoidPointer(long addr) {
047:                byteBase = new ByteBase(addr);
048:            }
049:
050:            VoidPointer(VoidPointer p) {
051:                byteBase = p.byteBase;
052:            }
053:
054:            VoidPointer(ByteBase base) {
055:                this .byteBase = base;
056:            }
057:
058:            public boolean isDirect() {
059:                return byteBase.isDirect();
060:            }
061:
062:            public abstract int size();
063:
064:            /**
065:             * Frees memory represented by this pointer. In case of direct object -
066:             * the native memory is deallocated. In case of locked Java memory - it is
067:             * released (back copying values to Java is not performed).
068:             * @see org.apache.harmony.misc.accessors.LockedArray#releaseNoCopy()
069:             */
070:            public void free() {
071:                byteBase.free();
072:                byteBase = null;
073:            }
074:
075:            /**
076:             * Returns the memory address for this pointer. Performs the explicit lock
077:             * of the pointed memory.
078:             * If this object is direct pointer to native memory - returns native address,
079:             * If this object reference to Java object, then Java object is locked and
080:             * memory address for locked Java object is returned.
081:             * Explicitly locked object should be released after usage.
082:             * @see #release()
083:             * @see #free()  h
084:             */
085:            public final long lock() {
086:                explicitlyLocked = true;
087:                return byteBase.longLockPointer();
088:            }
089:
090:            /**
091:             * Performs the explicit release of Java object. This method does nothing
092:             * if object is direct native pointer or non-locked Java memory.
093:             */
094:            public final void release() {
095:                explicitlyLocked = false;
096:                byteBase.unlock();
097:            }
098:
099:            public void unlock() {
100:                byteBase.unlock();
101:            }
102:
103:            /**
104:             * Performs the explicit releaseNoCopy of Java object. This method does nothing
105:             * if object is direct native pointer or non-locked Java memory.
106:             */
107:            public final void releaseNoCopy() {
108:                explicitlyLocked = false;
109:                byteBase.unlockNoCopy();
110:            }
111:
112:            public long longLockPointer() {
113:                explicitlyLocked = true;
114:                return byteBase.longLockPointer();
115:            }
116:
117:            /** performs short lock */
118:            public long shortLockPointer() {
119:                explicitlyLocked = true;
120:                return byteBase.shortLockPointer();
121:            }
122:
123:            /**
124:             * Internal long lock. Used in NativeBridge wrappers for native functions.
125:             * @return - memory address.
126:             */
127:            final long internalLongLock() {
128:                return byteBase.longLockPointer();
129:            }
130:
131:            /**
132:             * Internal short lock. Used in NativeBridge wrappers for native functions.
133:             * @return - memory address.
134:             */
135:            final long internalShortLock() {
136:                return byteBase.shortLockPointer();
137:            }
138:
139:            /**
140:             * Internal release. Unlocks objects if it was implicitly locked. This
141:             * methods don't release exlicitly locked Java objects.
142:             */
143:            final void internalRelease() {
144:                if (!explicitlyLocked) {
145:                    byteBase.unlock();
146:                }
147:            }
148:
149:            /**
150:             * Internal release. Unlocks objects if it was implicitly locked. This
151:             * methods don't release exlicitly locked Java objects. This methods gives
152:             * a hint, that values should not be copied back to Java object. Used for
153:             * "in" parameters of functions.
154:             */
155:            final void internalReleaseNoCopy() {
156:                if (!explicitlyLocked) {
157:                    byteBase.unlockNoCopy();
158:                }
159:            }
160:
161:            /**
162:             * Copies <code>length</code> bytes from src VoidPointer to this.
163:             * Offset in a destination is dstOffset. Starting offset in source
164:             * is always 0;
165:             *
166:             * @param src source byte base
167:             * @param dstOffset destination
168:             * @param length
169:             */
170:            public void copy(VoidPointer src, int dstOffset, int length) {
171:                byteBase.copy(src.byteBase, dstOffset, length);
172:            }
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.