From f710eebdeccb59b731b23ac42520e952d796c3c6 Mon Sep 17 00:00:00 2001 From: "gyeongseok.seo" Date: Wed, 9 Jan 2013 21:26:04 +0900 Subject: [PATCH] [Title] Fixed sdb server start sync bug. [Desc.] add sdb starting method [Issue] Change-Id: Ib32ffd2cc7a7f8cc4937a8083265a906d40e20e5 --- .../src/org/tizen/sdblib/DeviceMonitor.java | 1 + .../org/tizen/sdblib/SmartDevelopmentBridge.java | 52 +++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/DeviceMonitor.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/DeviceMonitor.java index 394dac6..27a3c46 100644 --- a/org.tizen.common.sdblib/src/org/tizen/sdblib/DeviceMonitor.java +++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/DeviceMonitor.java @@ -213,6 +213,7 @@ final class DeviceMonitor { SocketChannel sdbChannel = null; try { sdbChannel = SocketChannel.open(SmartDevelopmentBridge.getSocketAddress()); + mServer.setStarted(true); sdbChannel.socket().setTcpNoDelay(true); } catch (IOException e) { } diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridge.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridge.java index fab2404..5d8698d 100644 --- a/org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridge.java +++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridge.java @@ -24,6 +24,8 @@ import java.net.InetSocketAddress; import java.net.UnknownHostException; import java.security.InvalidParameterException; import java.util.ArrayList; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; /** * A connection to the host-side smart development bridge (sdb) @@ -48,6 +50,7 @@ public final class SmartDevelopmentBridge { /** Full path to sdb. */ private String mSdbOsLocation = null; + protected Lock lock = new ReentrantLock(); private boolean mStarted = false; private DeviceMonitor mDeviceMonitor; @@ -461,7 +464,6 @@ public final class SmartDevelopmentBridge { */ boolean start() { - mStarted = true; // now that the bridge is connected, we start the underlying services. mDeviceMonitor = new DeviceMonitor(this); mDeviceMonitor.start(); @@ -487,7 +489,7 @@ public final class SmartDevelopmentBridge { return false; } - mStarted = false; + setStarted(false); return true; } @@ -674,6 +676,7 @@ public final class SmartDevelopmentBridge { } Log.d(SDBLIB, "'sdb start-server' succeeded"); //$NON-NLS-1$ + setStarted(true); return true; } @@ -713,6 +716,7 @@ public final class SmartDevelopmentBridge { } Log.d(SDBLIB, "'sdb kill-server' succeeded"); //$NON-NLS-1$ + setStarted(false); return true; } @@ -890,5 +894,49 @@ public final class SmartDevelopmentBridge { } return result; } + + public void waitforStart() + { + while(!getStarted()) + { + synchronized ( this ) + { + try { + wait(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + + private boolean getStarted() + { + lock.lock(); + try + { + return mStarted; + }finally + { + lock.unlock(); + } + } + + public void setStarted(boolean isStarted) + { + lock.lock(); + try + { + mStarted = isStarted; + synchronized(this) + { + notifyAll(); + } + }finally + { + lock.unlock(); + } + } } -- 2.7.4