Changeset 49
- Timestamp:
- 07/01/08 14:53:20 (2 months ago)
- Files:
-
- trunk/libsipc/bindings/java/Makefile (modified) (5 diffs)
- trunk/libsipc/bindings/java/com/tresys/sipc/Sipc.java (modified) (6 diffs)
- trunk/libsipc/bindings/java/com/tresys/sipc/SipcMqueue.java (modified) (3 diffs)
- trunk/libsipc/bindings/java/com/tresys/sipc/SipcShm.java (modified) (3 diffs)
- trunk/libsipc/bindings/java/com/tresys/sipc/libsipc.java (deleted)
- trunk/libsipc/bindings/java/examples/Makefile (modified) (1 diff)
- trunk/libsipc/bindings/java/sipc.i (added)
- trunk/libsipc/bindings/java/sipc_wrap.c (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libsipc/bindings/java/Makefile
r30 r49 5 5 JAVAC ?= $(JAVA_HOME)/bin/javac 6 6 JAR ?= $(JAVA_HOME)/bin/jar 7 JAVADOC ?= %(JAVA_HOME)/bin/javadoc7 JAVADOC ?= $(JAVA_HOME)/bin/javadoc 8 8 9 9 TOP_SRCDIR ?= ../.. … … 14 14 SRC = com/tresys/sipc/BadKeyException.java \ 15 15 com/tresys/sipc/ConnectionException.java \ 16 com/tresys/sipc/libsipc.java \17 16 com/tresys/sipc/Sipc.java \ 18 17 com/tresys/sipc/SipcMqueue.java \ 19 18 com/tresys/sipc/SipcShm.java 19 SWIG_SRC = libsipc_t.java \ 20 sipcwrapperConstants.java \ 21 sipcwrapper.java \ 22 sipcwrapperJNI.java \ 23 SWIGTYPE_p_sipc_t.java 20 24 CLASSES = $(patsubst %.java,%.class,$(SRC)) 25 SWIG_CLASSES = $(patsubst %.java,com/tresys/sipc/%.class,$(SWIG_SRC)) 21 26 22 27 SOVERSION = 1 … … 36 41 SONAME = $(TARGET).$(SOVERSION) 37 42 LIBSO = $(TARGET).$(SOVERSION).$(RELEASE) 43 SWIG_WRAP = sipc_wrap.c 38 44 OBJS = sipc_wrap.o 39 45 40 all: $( JARTARGET) $(LIBSO)46 all: $(LIBSO) $(JARTARGET) 41 47 42 48 install: $(JARTARGET) $(LIBSO) … … 54 60 cd $(DESTDIR)/$(LIBDIR) && ln -sf $(LIBSO) $(TARGET).$(SOVERSION) 55 61 56 $(JARTARGET): $( CLASSES)57 $(JAR) cf $@ $ (CLASSES)62 $(JARTARGET): $(SWIG_CLASSES) $(CLASSES) 63 $(JAR) cf $@ $^ 58 64 59 65 %.class: %.java 60 $(JAVAC) $(JFLAGS) $< 66 $(JAVAC) $(AM_JFLAGS) $(JFLAGS) $< 67 68 $(firstword $(SWIG_CLASSES)): $(SWIG_SRC) 69 $(JAVAC) $(AM_JFLAGS) $(JFLAGS) -d . $^ 70 71 $(wordlist 2,$(words $(SWIG_CLASSES)), $(SWIG_CLASSES)): $(firstword $(SWIG_CLASSES)) 72 73 $(CLASSES): $(SWIG_CLASSES) 61 74 62 75 $(LIBSO): $(OBJS) … … 64 77 ln -sf $@ $(TARGET) 65 78 79 $(SWIG_SRC) $(SWIG_WRAP): sipc.i 80 swig -java -package com.tresys.sipc -o $(SWIG_WRAP) $(INCLUDEDIRS) $< 81 66 82 %.o: %.c 67 83 $(CC) $(AM_CFLAGS) $(CFLAGS) $(INCLUDEDIRS) $(JNI_CFLAGS) -fPIC -c -o $@ $< 68 84 69 javadoc: 70 $(JAVADOC) -d javadoc com.tresys.sipc85 javadoc: $(SWIG_CLASSES) 86 $(JAVADOC) -d javadoc $(SRC) $(SWIG_SRC) 71 87 72 88 clean: 73 -rm -f $( CLASSES) $(JARTARGET) $(TARGET) $(LIBSO) $(OBJS)89 -rm -f $(SWIG_WRAP) $(SWIG_SRC) $(CLASSES) $(SWIG_CLASSES) $(JARTARGET) $(TARGET) $(LIBSO) $(OBJS) 74 90 75 91 .PHONY: all install clean javadoc trunk/libsipc/bindings/java/com/tresys/sipc/Sipc.java
r24 r49 1 1 /* 2 * Copyright (C) 2006 , 2007Tresys Technology, LLC2 * Copyright (C) 2006 - 2008 Tresys Technology, LLC 3 3 * Developed Under US JFCOM Sponsorship 4 4 * … … 19 19 20 20 package com.tresys.sipc; 21 import com.tresys.sipc.libsipc_t; 22 import com.tresys.sipc.sipcwrapper; 21 23 22 24 /** … … 28 30 */ 29 31 public abstract class Sipc { 32 protected libsipc_t handle; /* internal handle */ 33 protected boolean isConnected = false; /* internal state flag */ 34 30 35 /** shared IPC key */ 31 public final String Key; 32 33 /** length of internal data buffer */ 34 public final long DATA_LEN; 35 36 /** length of system IPC bufer */ 37 public final long IPC_LEN; 38 39 /** determine which backend this uses */ 40 public abstract int GetIPCType(); 41 42 protected long handle; /* internal handle */ 43 44 protected long size_handle; /* internal message size handle */ 45 private java.nio.ByteBuffer dataPtr = null; /* internal pointer to data */ 46 47 private boolean isConnected = false; /* internal state flag */ 36 private final String key; 37 private int ipc_type; 48 38 49 39 /** 50 * Clean up a Sipc handle's resources. 40 * Clean up a Sipc handle's resources. 51 41 */ 52 42 protected void finalize() { 53 this.Disconnect(); 54 this.DestroyHandle(); 43 this.Close(); 55 44 } 56 45 57 46 /** 58 * Create a Sipc handle with specified key, internal buffer size and59 * system IPC buffer size.47 * Create a Sipc handle with specified key, role, and system 48 * IPC buffer size. 60 49 * 61 * @param key Path name representing an IPC key 62 * @param dataLength Size in bytes of the IPC handle's internal data buffer 63 * @param ipcLength Size in bytes of the system's IPC data buffer. This should not 64 * exceed any known system limits. 50 * @param key Path name representing an IPC key. 51 * @param role One of SIPC_CREATOR, SIPC_SENDER, or SIPC_RECEIVER. 52 * @param ipc_type One of SIPC_SYSV_SHM or SIPC_SYSV_MQUEUES. 53 * @param ipcLength Size in bytes of the system's IPC data buffer. 54 * This should not exceed any known system limits. 65 55 */ 66 p ublic Sipc(String key, long dataLength, long ipcLength){67 Key = key;68 handle = 0;69 DATA_LEN = dataLength;70 IPC_LEN = ipcLength;56 protected Sipc(String key, int role, int ipc_type, long ipcLength) throws Exception { 57 handle = new libsipc_t(key, role, ipc_type, ipcLength); 58 this.key = key; 59 this.ipc_type = ipc_type; 60 isConnected = true; 71 61 } 72 62 73 63 /** 74 * Initialize an IPC handle. This method needs to be called before Connect. 75 * 76 * @param write Flag indicating whether this instance is a writer or a reader 77 * @see #Connect() Connect 64 * Close the IPC handle, if it is still open. Then destroy 65 * the system IPC resource. 78 66 */ 79 public void Init(boolean write) { 80 handle = libsipc.sipc_init(Key, GetIPCType(), DATA_LEN, write ? 1 : 0); 81 isConnected = handle!=0; 82 size_handle=libsipc.sipc_create_length(); 83 } 84 85 /** 86 * Destroy an IPC handle. This function only destroys the 87 * resources associated with the handle itself; call 88 * Disconnect() to first disconnect. 89 */ 90 private void DestroyHandle() { 91 if(handle != 0) { 92 libsipc.sipc_destroy_handle(handle); 93 libsipc.sipc_destroy_length(size_handle); 94 size_handle=0; 95 handle = 0; 96 dataPtr = null; 97 } 98 } 99 100 /** 101 * Connect an IPC handle to its backend. 102 * Init() must be called prior to calling this. 103 * 104 * @throws ConnectionException if there is an error connecting 105 * @see #Init(boolean write) Init 106 */ 107 public boolean Connect() throws ConnectionException { 108 if(!isConnected) { 109 throw new ConnectionException("Attempt to connect failed"); 110 } 111 return isConnected; 67 public void DestroyHandle() { 68 this.Close(); 69 sipcwrapper.sipc_unlink(key, ipc_type); 112 70 } 113 71 … … 116 74 * 117 75 * @return true if the IPC handle is connected to its backend, 118 * false otherwise76 * false otherwise 119 77 */ 120 78 public boolean IsConnected() { … … 123 81 124 82 /** 125 * Disconnect an IPC handle from its backend. This function has no 83 * Disconnect an IPC handle from its backend. This function has no 126 84 * effect if the handle is already in a disconnected state. 127 85 */ 128 public void Disconnect() { 129 if(isConnected) { 86 public void Close() { 87 if (isConnected) { 88 handle.close(); 89 handle = null; 130 90 isConnected = false; 131 libsipc.sipc_disconnect(handle);132 dataPtr = null;133 91 } 134 92 } 135 93 136 /** 137 * Signal the sending application that a transmission has been successfully 94 /** 95 * Signal the sending application that a transmission has been successfully 138 96 * received and handled. This operation is not implemented by all backends. 139 97 */ 140 public void SipcRecvDone() {}98 public void SipcRecvDone() throws Exception {} 141 99 142 100 /** … … 144 102 * be in a connected state for this operation to succeed. 145 103 * 146 * @return A reference to the internal data pointer holding the 147 * received data, null on error.104 * @return A reference to the internal data pointer holding the 105 * received data, null on error. 148 106 */ 149 public java.nio.ByteBuffer ReadData() { 150 return libsipc.sipc_recv_data(handle, GetIPCType(), size_handle); 107 public byte[] ReadData() throws Exception { 108 if (isConnected) { 109 return handle.recv_data(); 110 } 111 else { 112 throw new ConnectionException("Handle was closed."); 113 } 151 114 } 152 115 153 116 /** 154 * Returns the size of the last successful ReadData() operation. 155 * This should be identical to the capacity of the buffer returned by 156 * ReadData(). Return value is undefined if ReadData has not been called. 157 * 158 * @return The size of the buffer returned by the most recent call to ReadData() 117 * Get a reference to the IPC handle's internal data buffer. 118 * This buffer's contents will sent data to an IPC channel 119 * upon calls to SendData(). The IPC handle must be in a 120 * connected state for this to succeed. 121 * 122 * @return A reference to the IPC handle's internal data buffer. 159 123 */ 160 public int GetReadSize() { 161 return libsipc.sipc_get_length(size_handle); 162 } 163 /** 164 * Get a reference to the IPC handle's internal data buffer. 165 * This buffer may be used to send data to or receive data from 166 * an IPC channel. The IPC handle must be initialized first. 167 * 168 * @return A reference to the IPC handle's internal data buffer 169 * @see #Init(boolean write) Init 170 */ 171 public java.nio.ByteBuffer GetDataPtr() { 172 dataPtr = libsipc.sipc_get_data_ptr(handle); 173 174 175 return dataPtr; 124 public java.nio.ByteBuffer GetDataPtr() throws Exception { 125 if (isConnected) { 126 return handle.get_data_ptr(); 127 } 128 else { 129 throw new ConnectionException("Handle was closed."); 130 } 176 131 } 177 132 178 133 /** 179 * Send data to a communications channel. The IPC handle must be in a 134 * Send data to a communications channel. The data came from 135 * the most recent call to GetDataPtr(). The IPC handle must 136 * be in a connected state for this to succeed. 137 * 138 * @param len Length of the message to be sent. 139 */ 140 public void SendData(int len) throws Exception { 141 if (isConnected) { 142 java.nio.ByteBuffer b = GetDataPtr(); 143 if (len > b.limit()) { 144 throw new IndexOutOfBoundsException("Len set to " + len + ", but buffer's limit was " + b.limit()); 145 } 146 handle.send_data(len); 147 } 148 else { 149 throw new ConnectionException("Handle was closed."); 150 } 151 } 152 153 /** 154 * Send data to a communications channel. The data came from 155 * the most recent call to GetDataPtr(); the entire buffer's 156 * contents will be sent. The IPC handle must be in a 180 157 * connected state for this to succeed. 181 *182 * @param len Length of the message to be sent183 * @return 0 on success, <0 on error.184 * @see #Connect() Connect185 158 */ 186 public int SendData(int len) { 187 return libsipc.sipc_send_data(handle, len); 188 } 189 190 /** 191 * Send data to the communications channel. The amount of data to 192 * send is determined by the current limit of the data buffer. 193 * 194 * @return 0 on success, <0 on error 195 * @see #SendData(int) SendData(int) 196 */ 197 public int SendData() { 198 return SendData(dataPtr.limit()); 159 public void SendData() throws Exception { 160 if (isConnected) { 161 java.nio.ByteBuffer b = GetDataPtr(); 162 handle.send_data(b.limit()); 163 } 164 else { 165 throw new ConnectionException("Handle was closed."); 166 } 199 167 } 200 168 } trunk/libsipc/bindings/java/com/tresys/sipc/SipcMqueue.java
r1 r49 1 1 /* 2 * Copyright (C) 2006 , 2007Tresys Technology, LLC2 * Copyright (C) 2006 - 2008 Tresys Technology, LLC 3 3 * Developed Under US JFCOM Sponsorship 4 4 * … … 20 20 package com.tresys.sipc; 21 21 22 import com.tresys.sipc.sipcwrapperConstants.*; 23 22 24 /** 23 25 * SYSV message queue backend implementation. 24 * 26 * 25 27 * @author David Windsor <dwindsor@tresys.com> 26 28 * @author Norman Patrick <npatrick@tresys.com> … … 32 34 * queue backed communications channel. 33 35 * 34 * @param key Pathname of IPC key, as understood by ftok(1) 35 * @param dataLength Size in bytes of handle's internal data buffer 36 * @param ipcLength Size in bytes of the system's SYSV message queue buffers. 37 * Fragmentation will occur if the handle's internal data buffer 38 * is larger than the system's data buffer. 36 * @param key Pathname of IPC key, as understood by ftok(1). 37 * @param role One of SIPC_CREATOR, SIPC_SENDER, or SIPC_RECEIVER. 38 * @param ipcLength Size in bytes of the system's IPC data buffer. 39 * This should not exceed any known system limits. 39 40 */ 40 public SipcMqueue(String key, long dataLength, long ipcLength){41 super(key, dataLength, ipcLength);41 public SipcMqueue(String key, int role, long ipcLength) throws Exception { 42 super(key, role, sipcwrapperConstants.SIPC_SYSV_MQUEUES, ipcLength); 42 43 } 43 44 /**45 * Create a SYSV message queue.46 * <p>47 * This function performs privileged operations and should not be48 * called by normal users. Creator processes are the only intended49 * users of this method.50 *51 * @throws BadKeyException if the key is not valid. The key52 * must be a valid pathname, as understood by ftok(1).53 * @see #Destroy(String key) Destroy54 */55 public static void Create(String key) throws BadKeyException {56 int id = libsipc.sipc_create(key, libsipc.SIPC_SYSV_MQUEUES);57 58 if(id < 0) {59 throw new BadKeyException("Unable to create message queue.");60 }61 }62 63 /**64 * Destroy a SYSV message queue.65 * <p>66 * This function performs privileged operations and should not be67 * called by normal users. Destroyer processes are the only intended68 * users of this function.69 *70 * @see #Create(String key) Create71 */72 public static void Destroy(String key) {73 libsipc.sipc_destroy_resource(key, libsipc.SIPC_SYSV_MQUEUES);74 }75 76 /**77 * Determine which type of backend this is.78 *79 * @return An integer representing SYSV message queues80 */81 public int GetIPCType() {82 return libsipc.SIPC_SYSV_MQUEUES;83 }84 85 44 } trunk/libsipc/bindings/java/com/tresys/sipc/SipcShm.java
r1 r49 1 1 /* 2 * Copyright (C) 2006 , 2007Tresys Technology, LLC2 * Copyright (C) 2006 - 2008 Tresys Technology, LLC 3 3 * Developed Under US JFCOM Sponsorship 4 4 * … … 20 20 package com.tresys.sipc; 21 21 22 import com.tresys.sipc.sipcwrapperConstants.*; 23 22 24 /** 23 25 * SYSV shared memory backend implementation. … … 32 34 * memory backed communications channel. 33 35 * 34 * @param key Pathname of IPC key, as understood by ftok(1) 35 * @param dataLength Size in bytes of handle's internal data buffer 36 * @param ipcLength Size in bytes of the system's SYSV message queue buffers. 37 * Fragmentation will occur if the handle's internal data buffer 38 * is larger than the system's data buffer. 36 * @param key Pathname of IPC key, as understood by ftok(1). 37 * @param role One of SIPC_CREATOR, SIPC_SENDER, or SIPC_RECEIVER. 38 * @param ipcLength Size in bytes of the system's IPC data buffer. 39 * This should not exceed any known system limits. 39 40 */ 40 public SipcShm(String key, long dataLength, long ipcLength){41 super(key, dataLength, ipcLength);41 public SipcShm(String key, int role, long ipcLength) throws Exception { 42 super(key, role, sipcwrapperConstants.SIPC_SYSV_SHM, ipcLength); 42 43 } 43 44 44 45 /** 45 * Create a SYSV shared memory segment. 46 * <p> 47 * This function performs privileged operations and should not be 48 * called by normal users. Creator processes are the only intended 49 * users of this function. 50 * 51 * @see #Destroy(String key) Destroy 46 * Signal the sending application that a transmission has been 47 * successfully received and handled. 52 48 */ 53 public static void Create(String key) throws BadKeyException { 54 int id = libsipc.sipc_create(key, libsipc.SIPC_SYSV_SHM); 55 56 if(id < 0) { 57 throw new BadKeyException("Unable to create shared memory segment."); 49 public void SipcRecvDone() throws Exception { 50 if (isConnected) { 51 handle.shm_recv_done(); 52 } 53 else { 54 throw new ConnectionException("Handle was closed."); 58 55 } 59 56 } 60 61 /**62 * Destroy a SYSV shared memory segment.63 * <p>64 * This function performs privileged operations and should not be65 * called by normal users. Destroyer processes are the only intended66 * users of this function.67 *68 * @see #Create(String key) Create69 */70 public static void Destroy(String key) {71 libsipc.sipc_destroy_resource(key, libsipc.SIPC_SYSV_SHM);72 }73 74 /**75 * Determine which type of backend this is.76 *77 * @return An integer representing SYSV shared memory78 */79 public int GetIPCType() {80 return libsipc.SIPC_SYSV_SHM;81 }82 83 /**84 * Signal the sender that we are finished processing85 * the data contained in the shared memory segment.86 * This will unblock the sender, potentially clobbering87 * the contents of the shared memory segment.88 */89 public void SipcRecvDone() {90 libsipc.sipc_shm_recv_done(this.handle);91 }92 57 } trunk/libsipc/bindings/java/examples/Makefile
r3 r49 1 FILES=$(wildcard *.java) 2 CLASSES=$(FILES:.java=.class) 3 CLASSPATH=.:.. 1 JAVA_HOME ?= /usr/java/default 2 JAVAC ?= $(JAVA_HOME)/bin/javac 4 3 5 # uncomment this region for gcj 6 # JFLAGS=-cp $(CLASSPATH) -1.5 7 # ifeq ($(DEBUG),1) 8 # JFLAGS+=-warn:+null 9 # endif 4 AM_JFLAGS = -cp ../libsipc-1.0.jar 10 5 11 # use this region for sun's java 12 JFLAGS=-cp $(CLASSPATH) -source 1.5 6 SRC = MQ_Binary_Reader.java \ 7 MQ_Creator.java \ 8 MQ_Destroyer.java \ 9 MQ_Reader.java \ 10 MQ_Sender.java \ 11 SHM_Creator.java \ 12 SHM_Destroyer.java \ 13 SHM_Reader.java \ 14 SHM_Sender.java 15 CLASSES = $(patsubst %.java,%.class,$(SRC)) 13 16 14 17 SIPC_KEYS=sipc_mq_key sipc_shm_key 15 18 16 all: $(CLASSES) 17 touch $(SIPC_KEYS) 19 all: $(SIPC_KEYS) $(CLASSES) 18 20 19 .SUFFIXES : .java .class 21 $(SIPC_KEYS): 22 touch $@ 20 23 21 .java.class: 22 javac$(JFLAGS) $<24 %.class: %.java 25 $(JAVAC) $(AM_JFLAGS) $(JFLAGS) $< 23 26 24 .PHONY clean:27 .PHONY: clean 25 28 rm -f *.class core $(SIPC_KEYS)
