skin: modified sendToQemuInternal function
authorgiwoong.kim <giwoong.kim@samsung.com>
Thu, 28 Feb 2013 09:14:06 +0000 (18:14 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Thu, 28 Feb 2013 09:14:06 +0000 (18:14 +0900)
Skin was not necessary to create output stream
at each sendToQemu.

Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java
tizen/src/skin/client/src/org/tizen/emulator/skin/comm/sock/SocketCommunicator.java

index 13f7e96bdf7a614ab2c33bbb97e5e8da56f4b0b8..d6f72d5af1c7e97140be564679b660ebd83102fa 100644 (file)
@@ -238,6 +238,8 @@ public class EmulatorSkinMain {
                                strVersion = reader.readLine();
 
                                reader.close();
+                       } else {
+                               logger.info("cannot find version file" + versionFilePath);
                        }
 
                        logger.info("SDK version : " + strVersion);
index 14d20e7367c6e8431f13b1173edbc6a0e1c8468d..2ce38829531368656bb4252b6424177097fc9db2 100644 (file)
@@ -73,9 +73,10 @@ public class SocketCommunicator implements ICommunicator {
                private Timer timer;
                
                private DataTranfer() {
+                       /* do nothing */
                }
 
-               private void setData( byte[] data ) {
+               private void setData(byte[] data) {
                        this.receivedData = data;
                        isTransferState = false;
                }
@@ -120,6 +121,9 @@ public class SocketCommunicator implements ICommunicator {
        private Thread sendThread;
        private LinkedList<SkinSendData> sendQueue;
 
+       private ByteArrayOutputStream bao;
+       private DataOutputStream dataOutputStream;
+
        public SocketCommunicator(EmulatorConfig config, int uId, EmulatorSkin skin) {
 
                this.config = config;
@@ -154,6 +158,8 @@ public class SocketCommunicator implements ICommunicator {
                        logger.log( Level.SEVERE, e.getMessage(), e );
                }
 
+               this.bao = new ByteArrayOutputStream();
+               this.dataOutputStream = new DataOutputStream(bao);
        }
 
        public void setInitialData(long data) {
@@ -483,68 +489,66 @@ public class SocketCommunicator implements ICommunicator {
        }
        
        @Override
-       public void sendToQEMU( SendCommand command, ISendData data ) {
-
-               synchronized ( sendQueue ) {
-                       if ( MAX_SEND_QUEUE_SIZE < sendQueue.size() ) {
-                               logger.warning( "Send queue size exceeded max value, do not push data into send queue." );
+       public void sendToQEMU(SendCommand command, ISendData data) {
+               synchronized(sendQueue) {
+                       if (MAX_SEND_QUEUE_SIZE < sendQueue.size()) {
+                               logger.warning(
+                                               "Send queue size exceeded max value, do not push data into send queue.");
                        } else {
-                               sendQueue.add( new SkinSendData( command, data ) );
+                               sendQueue.add(new SkinSendData(command, data));
                                sendQueue.notifyAll();
                        }
                }
-
        }
        
-       private void sendToQEMUInternal( SkinSendData sendData ) {
-
+       private void sendToQEMUInternal(SkinSendData sendData) {
                try {
 
-                       if( null == sendData ) {
+                       if (null == sendData) {
                                return;
                        }
                        
                        SendCommand command = sendData.getCommand();
                        ISendData data = sendData.getSendData();
-                       
-                       reqId = ( Integer.MAX_VALUE == reqId ) ? 0 : ++reqId;
-                       
-                       ByteArrayOutputStream bao = new ByteArrayOutputStream();
-                       DataOutputStream dataOutputStream = new DataOutputStream( bao );
 
-                       dataOutputStream.writeInt( uId );
-                       dataOutputStream.writeInt( reqId );
-                       dataOutputStream.writeShort( command.value() );
+                       reqId = (Integer.MAX_VALUE == reqId) ? 0 : ++reqId;
+
+                       dataOutputStream.writeInt(uId);
+                       dataOutputStream.writeInt(reqId);
+                       dataOutputStream.writeShort(command.value());
 
                        short length = 0;
-                       if ( null == data ) {
+                       if (null == data) {
                                length = 0;
-                               dataOutputStream.writeShort( length );
+                               dataOutputStream.writeShort(length);
                        } else {
                                byte[] byteData = data.serialize();
                                length = (short) byteData.length;
-                               dataOutputStream.writeShort( length );
-                               dataOutputStream.write( byteData );
+                               dataOutputStream.writeShort(length);
+                               dataOutputStream.write(byteData);
                        }
 
                        dataOutputStream.flush();
 
-                       dos.write( bao.toByteArray() );
+                       dos.write(bao.toByteArray());
                        dos.flush();
 
-                       if ( logger.isLoggable( Level.FINE ) ) {
-                               logger.fine( "[Socket] write - uid:" + uId + ", reqId:" + reqId + ", command:" + command.value()
-                                               + " - " + command.toString() + ", length:" + length );
+                       bao.reset();
+
+                       if (logger.isLoggable(Level.FINE)) {
+                               logger.fine("[Socket] write - uid:" + uId +
+                                               ", reqId:" + reqId + ", command:" + command.value()
+                                               + " - " + command.toString() + ", length:" + length);
                        }
 
-                       if ( 0 < length ) {
-                               if ( logger.isLoggable( Level.FINE ) ) {
-                                       logger.fine( "[Socket] data  - " + data.toString() );
+                       if (0 < length) {
+                               if (logger.isLoggable(Level.FINE)) {
+                                       logger.fine("[Socket] data  - " + data.toString());
                                }
                        }
 
-               } catch ( IOException e ) {
-                       logger.log( Level.SEVERE, e.getMessage(), e );
+               } catch (IOException e) {
+                       logger.log(Level.SEVERE, e.getMessage(), e);
                }
 
        }
@@ -644,6 +648,13 @@ public class SocketCommunicator implements ICommunicator {
 
                IOUtil.closeSocket(socket);
 
+               try {
+                       bao.close();
+                       dataOutputStream.close();
+               } catch (IOException e) {
+                       e.printStackTrace();
+               }
+
                synchronized (this) {
                        skin.shutdown();
                }