Changeset 54

Show
Ignore:
Timestamp:
07/17/08 12:54:18 (5 months ago)
Author:
jtang
Message:

Added ioctl() to Java bindings.
Clean up and Java unit tests.
Make C test script executable.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libsipc/bindings/java/com/tresys/sipc/Sipc.java

    r50 r54  
    3030 */ 
    3131public abstract class Sipc { 
     32        public final static int CREATOR = sipcwrapperConstants.SIPC_CREATOR; 
     33        public final static int SENDER =  sipcwrapperConstants.SIPC_SENDER; 
     34        public final static int RECEIVER =  sipcwrapperConstants.SIPC_RECEIVER; 
     35        public final static int BLOCK = sipcwrapperConstants.SIPC_BLOCK; 
     36        public final static int NOBLOCK = sipcwrapperConstants.SIPC_NOBLOCK; 
     37 
    3238        protected libsipc_t handle; /* internal handle */ 
    3339        protected boolean isConnected = false; /* internal state flag */ 
     
    3642        /** shared IPC key */ 
    3743        private final String key; 
     44 
     45        /** the type of IPC, either SIPC_SYSV_SHM or SIPC_SYSV_MQUEUES */ 
    3846        private int ipc_type; 
    3947 
     
    5058         * 
    5159         * @param key  Path name representing an IPC key. 
    52          * @param role One of SIPC_CREATOR, SIPC_SENDER, or SIPC_RECEIVER. 
     60         * @param role One of Sipc.CREATOR, Sipc.SENDER, or Sipc.RECEIVER. 
    5361         * @param ipc_type One of SIPC_SYSV_SHM or SIPC_SYSV_MQUEUES. 
    5462         * @param ipcLength  Size in bytes of the system's IPC data buffer. 
     
    5664         */ 
    5765        protected Sipc(String key, int role, int ipc_type, long ipcLength) throws Exception { 
     66                if (role != Sipc.CREATOR && role != Sipc.SENDER && role != Sipc.RECEIVER) { 
     67                        throw new Error("Role must be one of Sipc.CREATOR, Sipc.SENDER, or Sipc.RECEIVER"); 
     68                } 
     69                if (ipc_type != sipcwrapperConstants.SIPC_SYSV_MQUEUES && 
     70                    ipc_type != sipcwrapperConstants.SIPC_SYSV_SHM) { 
     71                        throw new Error("IPC type must be one of sipcwrapperConstants.SIPC_SYSV_MQUEUES or sipcwrapperConstants.SIPC_SYSV_SHM"); 
     72                } 
    5873                handle = new libsipc_t(key, role, ipc_type, ipcLength); 
    5974                this.key = key; 
     
    95110 
    96111        /** 
    97          * Signal the sending application that a transmission has been successfully 
    98          * received and handled.  This operation is not implemented by all backends. 
     112         * Signal the sending application that a transmission has been 
     113         * successfully received and handled.  This operation is not 
     114         * implemented by all backends. 
    99115         */ 
    100116        public void SipcRecvDone() throws Exception {} 
     
    104120         * be in a connected state for this operation to succeed. 
    105121         * 
    106          * @return  A reference to the internal data pointer holding the 
    107          *          received data, null on error. 
     122         * @return A reference to the internal data pointer holding 
     123         * the received data, or NULL if the channel is set to 
     124         * non-blocking read and there was nothing available to be 
     125         * read. 
    108126         */ 
    109127        public byte[] ReadData() throws Exception { 
     
    175193                } 
    176194        } 
     195 
     196        /** 
     197         * Modify the behavior of an open communications channel. 
     198         * 
     199         * @param request If Sipc.BLOCK, set the channel to block when 
     200         * reading.  (This is the default).  If Sipc.NONBLOCK, then 
     201         * set the channel to not block when reading. 
     202         */ 
     203        public void IOCtl(int request) throws Exception { 
     204                if (isConnected) { 
     205                        handle.ioctl(request); 
     206                } 
     207                else { 
     208                        throw new ConnectionException("Handle was closed."); 
     209                } 
     210        } 
    177211} 
  • trunk/libsipc/bindings/java/com/tresys/sipc/SipcMqueue.java

    r50 r54  
    3535         * 
    3636         * @param key  Pathname of IPC key, as understood by ftok(1). 
    37          * @param role One of SIPC_CREATOR, SIPC_SENDER, or SIPC_RECEIVER. 
     37         * @param role One of Sipc.CREATOR, Sipc.SENDER, or Sipc.RECEIVER. 
    3838         * @param ipcLength  Size in bytes of the system's IPC data buffer. 
    3939         *                   This should not exceed any known system limits. 
  • trunk/libsipc/bindings/java/com/tresys/sipc/SipcShm.java

    r50 r54  
    3535         * 
    3636         * @param key  Pathname of IPC key, as understood by ftok(1). 
    37          * @param role One of SIPC_CREATOR, SIPC_SENDER, or SIPC_RECEIVER. 
     37         * @param role One of Sipc.CREATOR, Sipc.SENDER, or Sipc.RECEIVER. 
    3838         * @param ipcLength  Size in bytes of the system's IPC data buffer. 
    3939         *                   This should not exceed any known system limits. 
  • trunk/libsipc/bindings/java/sipc.i

    r49 r54  
    150150                BEGIN_EXCEPTION 
    151151                if (sipc_recv_data(self->sipc, &data, &len) < 0) { 
     152                        if (errno == EAGAIN) { 
     153                                return NULL; 
     154                        } 
    152155                        SWIG_exception(SWIG_RuntimeError, strerror(errno)); 
    153156                } 
  • trunk/libsipc/bindings/java/tests/MQ_Creator.java

    r52 r54  
    3333        public static void main(String[] args) { 
    3434                try { 
    35                     Sipc sipc = new SipcMqueue(sipc_key, sipcwrapperConstants.SIPC_CREATOR, 8196); 
     35                    Sipc sipc = new SipcMqueue(sipc_key, Sipc.CREATOR, 8196); 
    3636                    sipc.Close(); 
    3737                } catch (Exception e) { 
  • trunk/libsipc/bindings/java/tests/MQ_Reader.java

    r52 r54  
    4747                /* Create and initialize the IPC handle */ 
    4848                try { 
    49                         queue = new SipcMqueue(sipc_key, sipcwrapperConstants.SIPC_RECEIVER, ipc_len); 
     49                        queue = new SipcMqueue(sipc_key, Sipc.RECEIVER, ipc_len); 
    5050                } 
    5151                catch (Exception e) { 
     
    5959                                "out.dat"); 
    6060                        /* Read data from the queue */ 
     61                        byte[] bbuf; 
    6162                        while (true) { 
    62                                 byte[] bbuf = queue.ReadData(); 
     63                                bbuf = queue.ReadData(); 
    6364                                /* Check for an end of transmission marker */ 
    6465                                if (bbuf.length == 11) { 
     
    7172                        } 
    7273 
     74                        /* Try a non-blocking read */ 
     75                        queue.IOCtl(Sipc.NOBLOCK); 
     76                        bbuf = queue.ReadData(); 
     77                        if (bbuf != null) { 
     78                                throw new Exception("Non-blocking read returned something."); 
     79                        } 
    7380                        fileOut.close(); 
    7481                } 
  • trunk/libsipc/bindings/java/tests/MQ_Sender.java

    r52 r54  
    4949                try { 
    5050                        /* Create and initialize the IPC handle */ 
    51                         queue = new SipcMqueue(sipc_key, sipcwrapperConstants.SIPC_SENDER, ipc_len); 
     51                        queue = new SipcMqueue(sipc_key, Sipc.SENDER, ipc_len); 
    5252                        /* Read data from the file and send it to the channel */ 
    5353                        stream = new FileInputStream(filename); 
  • trunk/libsipc/bindings/java/tests/SHM_Creator.java

    r52 r54  
    3333        public static void main(String[] args) { 
    3434                try { 
    35                     Sipc sipc = new SipcShm(sipc_key, sipcwrapperConstants.SIPC_CREATOR, 8192); 
     35                    Sipc sipc = new SipcShm(sipc_key, Sipc.CREATOR, 8192); 
    3636                    sipc.Close(); 
    3737                } catch (Exception e) { 
  • trunk/libsipc/bindings/java/tests/SHM_Reader.java

    r52 r54  
    4646                /* Create and initialize the IPC handle */ 
    4747                try { 
    48                         shm = new SipcShm(sipc_key, sipcwrapperConstants.SIPC_RECEIVER, ipc_len); 
     48                        shm = new SipcShm(sipc_key, Sipc.RECEIVER, ipc_len); 
    4949                } catch (Exception e) { 
    5050                        e.printStackTrace(); 
     
    6060                                "out.dat"); 
    6161                        /* Read data from the shared memory */ 
     62                        byte[] bbuf; 
    6263                        while(true) { 
    63                                 byte[] bbuf = shm.ReadData(); 
     64                                bbuf = shm.ReadData(); 
    6465                                /* Check for the end of transmission marker */ 
    6566                                if (IsEndXmit(bbuf)) { 
     
    6970                                fileOut.write(bbuf); 
    7071                                shm.RecvDone(); 
     72                        } 
     73 
     74                        /* Try a non-blocking read */ 
     75                        shm.IOCtl(Sipc.NOBLOCK); 
     76                        bbuf = shm.ReadData(); 
     77                        if (bbuf != null) { 
     78                                throw new Exception("Non-blocking read returned something."); 
    7179                        } 
    7280                } 
  • trunk/libsipc/bindings/java/tests/SHM_Sender.java

    r52 r54  
    4949                try { 
    5050                        /* Create and initialize the IPC handle */ 
    51                         shm = new SipcShm(sipc_key, sipcwrapperConstants.SIPC_SENDER, ipc_len); 
     51                        shm = new SipcShm(sipc_key, Sipc.SENDER, ipc_len); 
    5252 
    5353                        /* Read data from the file and send it across the channel */ 
  • trunk/libsipc/tests/run_tests.sh

    • Property svn:executable set to *