summaryrefslogtreecommitdiff
path: root/org.tizen.common.sdblib
diff options
context:
space:
mode:
authorBonyong.lee <bonyong.lee@samsung.com>2013-07-29 11:22:59 +0900
committerBonyong.lee <bonyong.lee@samsung.com>2013-07-29 11:22:59 +0900
commit8be00d9ae3f4abc5b787825a53eef424d39bbcc7 (patch)
tree87dcf2f917bfe4a9a27c6802ac53ff7cc68cb1f9 /org.tizen.common.sdblib
parent80e39d7cb6321c3d13f163985215d3710a76652c (diff)
downloadcommon-eplugin-8be00d9ae3f4abc5b787825a53eef424d39bbcc7.tar.gz
common-eplugin-8be00d9ae3f4abc5b787825a53eef424d39bbcc7.tar.bz2
common-eplugin-8be00d9ae3f4abc5b787825a53eef424d39bbcc7.zip
[Title] Refactoring as Protex's result
[Desc.] [Issue]
Diffstat (limited to 'org.tizen.common.sdblib')
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java19
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/DeviceMonitor.java70
-rwxr-xr-xorg.tizen.common.sdblib/src/org/tizen/sdblib/IDevice.java126
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/SdbHelper.java212
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridge.java251
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridgetConstants.java23
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/command/Command.java2
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/command/matcher/MultiMatcher.java2
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/exception/SyncException.java28
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/FileEntryFactory.java1
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/service/CrashReportService.java2
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryInputStream.java18
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryOutputStream.java22
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncResult.java35
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncService.java94
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncServiceConstants.java76
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncServiceReturnCode.java72
-rwxr-xr-xorg.tizen.common.sdblib/src/org/tizen/sdblib/util/ArrayHelper.java65
-rwxr-xr-xorg.tizen.common.sdblib/src/org/tizen/sdblib/util/ByteUtil.java122
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/util/DeviceUtil.java3
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/util/LogLevel.java40
21 files changed, 691 insertions, 592 deletions
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java
index 4a17ffa5e..7d3bfbe36 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java
@@ -412,23 +412,8 @@ implements IDevice
execute( command ).in( this, receiver );
}
- /**
- * Executes a shell command on the device and retrieve the output. The output is
- * handed to <var>rcvr</var> as it arrives.
- *
- * @param command the shell command to execute
- * @param receiver the {@link IShellOutputReceiver} that will receives the output of the shell
- * command
- * @param maxTimeToOutputResponse max time between command output. If more time passes
- * between command output, the method will throw
- * {@link ShellCommandUnresponsiveException}. A value of 0 means the method will
- * wait forever for command output and never throw.
- * @throws TimeoutException in case of timeout on the connection when sending the command.
- * @throws SdbCommandRejectedException if sdb rejects the command
- * @throws ShellCommandUnresponsiveException in case the shell command doesn't send any output
- * for a period longer than <var>maxTimeToOutputResponse</var>.
- * @throws IOException in case of I/O error on the connection.
- *
+ /* (non-Javadoc)
+ * @see org.tizen.sdblib.IDevice#executeShellCommand(java.lang.String, org.tizen.sdblib.IShellOutputReceiver, int)
*/
public
void
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 dcba7aeaa..b305a3fe2 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/DeviceMonitor.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/DeviceMonitor.java
@@ -43,9 +43,8 @@ import org.tizen.sdblib.util.Log;
/**
* DeviceMonitor
- * <p/>
- * A Device monitor. This connects to the Smart Development Bridge and get device.
- * <p/>
+ *
+ * Monitor {@link IDevice}
*
* @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
*/
@@ -63,8 +62,6 @@ extends AbstractServer
*/
protected ArrayList<Device> devices = null;
- private byte[] mLengthBuffer = new byte[4];
-
private SocketChannel mMainSdbConnection = null;
private boolean mMonitoring = false;
private int mRestartAttemptCount = 0;
@@ -190,7 +187,7 @@ extends AbstractServer
try {
SdbHelper.write(mMainSdbConnection, request);
- SdbResponse resp = SdbHelper.readSdbResponse(mMainSdbConnection, false /* readDiagString */);
+ SdbResponse resp = SdbHelper.readSdbResponse(mMainSdbConnection);
if (resp.okay == false) {
// request was refused by sdb!
@@ -236,13 +233,13 @@ extends AbstractServer
}
}
- // now merge the new devices with the old ones.
updateDevices(list);
}
/**
- * Updates the device list with the new items received from the monitoring service.
- * @throws AsynchronousCloseException
+ * Update device as new infomations.
+ *
+ * @throws AsynchronousCloseException if device is disconnected before being processed
*/
protected
void
@@ -251,12 +248,7 @@ extends AbstractServer
)
throws AsynchronousCloseException
{
- // because we are going to call mServer.deviceDisconnected which will acquire this lock
- // we lock it first, so that the SmartDevelopmentBridge lock is always locked first.
synchronized (SmartDevelopmentBridge.getLock()) {
- // array to store the devices that must be queried for information.
- // it's important to not do it inside the synchronized loop as this could block
- // the whole workspace (this lock is acquired during build too).
final ArrayList<Device> devicesToQuery = new ArrayList<Device>();
if (null == this.devices )
{
@@ -265,69 +257,49 @@ extends AbstractServer
synchronized ( this )
{
- // For each device in the current list, we look for a matching the new list.
- // * if we find it, we update the current object with whatever new information
- // there is (mostly state change, if the device becomes ready, we query for build info).
- // We also remove the device from the new list to mark it as "processed"
- // * if we do not find it, we remove it from the current list.
- // Once this is done, the new list contains device we aren't monitoring yet, so we
- // add them to the list, and start monitoring them.
for ( int d = 0; d < devices.size() ; )
{
final Device device = devices.get(d);
- // look for a similar device in the new list.
int count = newList.size();
boolean foundMatch = false;
for (int dd = 0; dd < count; dd++) {
Device newDevice = newList.get(dd);
- // see if it matches in id and serial number.
if (newDevice.getSerialNumber().equals(device.getSerialNumber())) {
foundMatch = true;
- // update the name if needed.
if (!device.getDeviceName().equals(newDevice.getDeviceName())){
device.update(Device.CHANGE_NAME, newDevice.getDeviceName());
}
- // update the state if needed.
if (device.getState() != newDevice.getState()) {
device.setState(newDevice.getState());
- // should to check architecture if device is an
- // emulator and state changed from "off-lined" to "on-lined"
if (device.getState() == DeviceState.ONLINE) {
device.initialize();
Log.d("DeviceMonitor", "updateDevices: " + device.getSerialNumber() + " onlined");
device.update(Device.CHANGE_STATE, newDevice.getDeviceName());
}
}
- // remove the new device from the list since it's been used
newList.remove(dd);
break;
}
}
if (foundMatch == false) {
- // the device is gone, we need to remove it, and keep current index to process the next one.
removeDevice(device);
bridge.deviceDisconnected(device);
Log.d("DeviceMonitor", "updateDevices: " + device.getSerialNumber() + " off-lined");
} else {
- // process the next one
d++;
}
}
- // at this point we should still have some new devices in newList, so we process them.
for (Device newDevice : newList) {
- // should to check architecture if new device is an emulator on-lined
if ( isOnline( newDevice ) ) {
newDevice.initialize();
}
- // add them to the list
devices.add(newDevice);
- // look for their build info.
if ( isOnline( newDevice ) ) {
devicesToQuery.add(newDevice);
bridge.deviceConnected(newDevice);
@@ -342,16 +314,21 @@ extends AbstractServer
}
/**
- * Reads the length of the next message from a socket.
+ * Read from socket and parse to number
*
- * @param socket
- * The {@link SocketChannel} to read from.
- * @return the length, or 0 (zero) if no data is available from the socket.
- * @throws IOException
- * if the connection failed.
+ * @param socket socket to read from
+ * @param buffer buffer for data
+ * @return the length to be read
+ * @throws IOException if the connection failed.
*/
- private int readLength(SocketChannel socket, byte[] buffer) throws IOException {
- String msg = read(socket, buffer);
+ private
+ int
+ readLength(
+ final SocketChannel socket
+ )
+ throws IOException
+ {
+ String msg = read(socket, new byte[4]);
if (msg != null) {
try {
@@ -367,10 +344,11 @@ extends AbstractServer
}
/**
- * Fills a buffer from a socket.
+ * Read from socket and write to buffer
*
- * @param socket
- * @param buffer
+ * @param socket socket to read from
+ * @param buffer buffer for data
+ * @return the length to be read
* @return the content of the buffer as a string, or null if it failed to convert the buffer.
* @throws IOException
*/
@@ -437,7 +415,7 @@ extends AbstractServer
if (mMonitoring) {
// read the length of the incoming message
- int length = readLength(mMainSdbConnection, mLengthBuffer);
+ int length = readLength(mMainSdbConnection);
if (length >= 0) {
// read the incoming message
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/IDevice.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/IDevice.java
index 72fd89482..a5bdf79c5 100755
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/IDevice.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/IDevice.java
@@ -95,15 +95,15 @@ IDevice
/**
* Returns a {@link SyncService} object to push / pull files to and from the device.
*
- * @return <code>null</code> if the SyncService couldn't be created. This can happen if sdb
- * refuse to open the connection because the {@link IDevice} is invalid
- * (or got disconnected).
+ * @return device's {@link SyncService}
+ *
* @throws TimeoutException in case of timeout on the connection.
* @throws SdbCommandRejectedException if sdb rejects the command
* @throws IOException if the connection with sdb failed.
*/
- SyncService getSyncService()
- throws TimeoutException, SdbCommandRejectedException, IOException;
+ SyncService
+ getSyncService()
+ throws IOException;
/**
* Returns the root {@link FileEntry} for this device
@@ -120,7 +120,7 @@ IDevice
*
* @return file entry
*/
- FileEntry getFileEntry( final String path );
+ FileEntry getFileEntry( String path );
/**
* Executes a shell command on the device interactively and return SdbShellProcess
@@ -130,7 +130,11 @@ IDevice
*
* @see SdbShellProcess
*/
- SdbShellProcess executeShellCommand(String command) throws IOException;
+ SdbShellProcess
+ executeShellCommand(
+ String command
+ )
+ throws IOException;
/**
* Executes a shell command to the device promptly and return SdbShellProcess
@@ -140,70 +144,55 @@ IDevice
*
* @see SdbShellProcess
*/
- Process executeShellCommand(String command, boolean prompt) throws IOException;
+ Process
+ executeShellCommand(
+ String command,
+ boolean prompt
+ )
+ throws IOException;
/**
- * Executes a shell command on the device, and sends the result to a <var>receiver</var>
- * <p/>This is similar to calling
- * <code>executeShellCommand(command, receiver, SdbPreferences.getTimeOut())</code>.
+ * Executes a shell command on the device, and sends the result to a {@code receiver}
*
* @param command the shell command to execute
- * @param receiver the {@link IShellOutputReceiver} that will receives the output of the shell
- * command
- * @throws TimeoutException in case of timeout on the connection.
+ * @param receiver object to process result
+ *
+ * @throws TimeoutException if it timeout
* @throws SdbCommandRejectedException if sdb rejects the command
- * @throws ShellCommandUnresponsiveException in case the shell command doesn't send output
- * for a given time.
+ * @throws ShellCommandUnresponsiveException if the shell command doesn't send output for a given time.
* @throws IOException in case of I/O error on the connection.
*
* @see #executeShellCommand(String, IShellOutputReceiver, int)
* @see Preferences#getTimeOut()
*/
- void executeShellCommand(String command, IShellOutputReceiver receiver)
- throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException,
- IOException;
+ void
+ executeShellCommand(
+ String command,
+ IShellOutputReceiver receiver
+ )
+ throws IOException;
/**
- * Executes a shell command on the device, and sends the result to a <var>receiver</var>.
- * <p/><var>maxTimeToOutputResponse</var> is used as a maximum waiting time when expecting the
- * command output from the device.<br>
- * At any time, if the shell command does not output anything for a period longer than
- * <var>maxTimeToOutputResponse</var>, then the method will throw
- * {@link ShellCommandUnresponsiveException}.
- * <p/>For commands like log output, a <var>maxTimeToOutputResponse</var> value of 0, meaning
- * that the method will never throw and will block until the receiver's
- * {@link IShellOutputReceiver#isCancelled()} returns <code>true</code>, should be
- * used.
+ * Executes a shell command on the device, and sends the result to a {@code receiver}
*
* @param command the shell command to execute
- * @param receiver the {@link IShellOutputReceiver} that will receives the output of the shell
- * command
- * @param maxTimeToOutputResponse the maximum amount of time during which the command is allowed
- * to not output any response. A value of 0 means the method will wait forever
- * (until the <var>receiver</var> cancels the execution) for command output and
- * never throw.
- * @throws TimeoutException in case of timeout on the connection when sending the command.
- * @throws SdbCommandRejectedException if sdb rejects the command.
- * @throws ShellCommandUnresponsiveException in case the shell command doesn't send any output
- * for a period longer than <var>maxTimeToOutputResponse</var>.
+ * @param receiver object to process result
+ * @param maxTimeToOutputResponse time for waiting
+ *
+ * @throws TimeoutException if it timeout
+ * @throws SdbCommandRejectedException if sdb rejects the command
+ * @throws ShellCommandUnresponsiveException if the shell command doesn't send output for a given time.
* @throws IOException in case of I/O error on the connection.
*
- * @see Preferences#getTimeOut()
*/
- void executeShellCommand(String command, IShellOutputReceiver receiver,
- int maxTimeToOutputResponse)
- throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException,
- IOException;
+ void
+ executeShellCommand(
+ String command,
+ IShellOutputReceiver receiver,
+ int maxTimeToOutputResponse
+ )
+ throws IOException;
/**
- * Executes a sdb launch command on the device, and sends the result to a <var>receiver</var>.
- *
- * @param receiver the {@link IShellOutputReceiver} that will receives the output of the command
- * @param options arguments of the launch command
- * @throws IOException in case of I/O error on the connection
- */
-// public void executeLaunchCommand(IShellOutputReceiver receiver, String options) throws IOException;
-
- /**
* Creates a port forwarding between a local and a remote port.
*
* @param localPort the local port to forward
@@ -213,8 +202,12 @@ IDevice
* @throws SdbCommandRejectedException if sdb rejects the command
* @throws IOException in case of I/O error on the connection.
*/
- void createForward(int localPort, int remotePort)
- throws TimeoutException, SdbCommandRejectedException, IOException;
+ void
+ createForward(
+ int localPort,
+ int remotePort
+ )
+ throws IOException;
/**
* Removes a port forwarding between a local and a remote port.
@@ -226,13 +219,18 @@ IDevice
* @throws SdbCommandRejectedException if sdb rejects the command
* @throws IOException in case of I/O error on the connection.
*/
- void removeForward(int localPort, int remotePort)
- throws TimeoutException, SdbCommandRejectedException, IOException;
+ void
+ removeForward(
+ int localPort,
+ int remotePort
+ )
+ throws TimeoutException, SdbCommandRejectedException, IOException;
/**
* Returns application's installation path.
*/
- String getAppInstallPath();
+ String
+ getAppInstallPath();
/**
* Execute command and get result using {@code receiver}
@@ -242,7 +240,11 @@ IDevice
*
* @throws IOException If communication fail
*/
- void executeLaunchCommand(String command, IShellOutputReceiver receiver) throws IOException;
+ void executeLaunchCommand(
+ String command,
+ IShellOutputReceiver receiver
+ )
+ throws IOException;
/**
* Execute command and get result using {@code receiver}
@@ -252,5 +254,9 @@ IDevice
*
* @throws IOException If communication fail
*/
- void executeHostCommand(String command, IShellOutputReceiver receiver) throws IOException;
+ void executeHostCommand(
+ String command,
+ IShellOutputReceiver receiver
+ )
+ throws IOException;
}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/SdbHelper.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/SdbHelper.java
index dc44ecc7e..649e5e1b8 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/SdbHelper.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/SdbHelper.java
@@ -41,17 +41,10 @@ import org.tizen.sdblib.util.Log;
import org.tizen.sdblib.util.Preferences;
/**
- * Helper class to handle requests and connections to sdb.
- * <p/>{@link DebugBridgeServer} is the public API to connection to sdb, while {@link SdbHelper}
- * does the low level stuff.
- * <p/>This currently uses spin-wait non-blocking I/O. A Selector would be more efficient,
- * but seems like overkill for what we're doing here.
+ * Helper class to {@link SmartDevelopmentBridge}
*/
public class SdbHelper {
- // public static final long kOkay = 0x59414b4fL;
- // public static final long kFail = 0x4c494146L;
-
public static final int WAIT_TIME = 50; // spin-wait sleep, in ms
public static final String DEFAULT_ENCODING = "ISO-8859-1"; //$NON-NLS-1$
@@ -61,10 +54,6 @@ public class SdbHelper {
public static final Charset UTF_CHARSET = Charset.forName( OUTPUT_DECODING );
- /** do not instantiate */
- private SdbHelper() {
- }
-
/**
* convert string to bytes
*
@@ -148,39 +137,39 @@ public class SdbHelper {
* null.
*/
public static byte[] formSdbRequest(String req) {
- byte [] result;
- byte [] reqByte;
- byte [] lengthByte;
try {
- reqByte = string2bytes( req );
+ final byte[] reqByte = string2bytes( req );
//info about reqByte length with 4 digit ex) 001D
- lengthByte = String.format("%04X", reqByte.length).getBytes();
+ final byte[] lengthByte = String.format("%04X", reqByte.length).getBytes();
- result = new byte[reqByte.length + 4];
+ final byte[] result = new byte[reqByte.length + 4];
System.arraycopy(lengthByte, 0, result, 0, 4);
System.arraycopy(reqByte, 0, result, 4, reqByte.length);
return result;
- } catch (UnsupportedEncodingException uee) {
- uee.printStackTrace(); // not expected
+ } catch ( final UnsupportedEncodingException uee) {
+ Log.e( "Unsupported encoding. ", uee );
return null;
}
}
/**
- * Reads the response from sdb after a command.
- * @param chan The socket channel that is connected to sdb.
- * @param readDiagString If true, we're expecting an OKAY response to be
- * followed by a diagnostic string. Otherwise, we only expect the
- * diagnostic string to follow a FAIL.
+ * Read the response from sdb after a command.
+ *
+ * @param chan The socket channel to sdb
+ *
* @throws TimeoutException in case of timeout on the connection.
* @throws IOException in case of I/O error on the connection.
*/
- public static SdbResponse readSdbResponse(SocketChannel chan, boolean readDiagString)
- throws TimeoutException, IOException {
-
+ public static
+ SdbResponse
+ readSdbResponse(
+ final SocketChannel chan
+ )
+ throws IOException
+ {
SdbResponse resp = new SdbResponse();
byte[] reply = new byte[4];
@@ -189,54 +178,59 @@ public class SdbHelper {
if ( check( ID_OKAY, 0, reply, 0, 4 ) )
{
resp.okay = true;
- } else {
- readDiagString = true; // look for a reason after the FAIL
- resp.okay = false;
+
+ return resp;
}
+ resp.okay = false;
- // not a loop -- use "while" so we can use "break"
- while (readDiagString) {
- // length string is in next 4 bytes
- byte[] lenBuf = new byte[4];
- read(chan, lenBuf);
-
- String lenStr = replyToString(lenBuf);
-
- int len;
- try {
- len = Integer.parseInt(lenStr, 16);
- } catch (NumberFormatException nfe) {
- Log.w("sdb", "Expected digits, got '" + lenStr + "': "
- + lenBuf[0] + " " + lenBuf[1] + " " + lenBuf[2] + " "
- + lenBuf[3]);
- Log.w("sdb", "reply was " + replyToString(reply));
- break;
- }
-
- byte[] msg = new byte[len];
- read(chan, msg);
+ // length string is in next 4 bytes
+ byte[] lenBuf = new byte[4];
+ read(chan, lenBuf);
+
+ String lenStr = replyToString(lenBuf);
- resp.message = replyToString(msg);
- Log.v("sdb", "Got reply '" + replyToString(reply) + "', diag='"
- + resp.message + "'");
-
- break;
+ int len;
+ try {
+ len = Integer.parseInt(lenStr, 16);
+ } catch (NumberFormatException nfe) {
+ Log.w("sdb", "Expected digits, got '" + lenStr + "': "
+ + lenBuf[0] + " " + lenBuf[1] + " " + lenBuf[2] + " "
+ + lenBuf[3]);
+ Log.w("sdb", "reply was " + replyToString(reply));
+ return resp;
}
+
+ byte[] msg = new byte[len];
+ read(chan, msg);
+
+ resp.message = replyToString( msg );
+ Log.v("sdb", "Got reply '" + replyToString(reply) + "', diag='" + resp.message + "'");
+
return resp;
}
/**
- * Creates a port forwarding between a local and a remote port.
- * @param sdb the socket address to connect to sdb
- * @param device the device on which to do the port fowarding
- * @param localPort the local port to forward
- * @param remotePort the remote port.
+ * Make port forward
+ *
+ * @param sdb sdb
+ * @param device device for port forwarding
+ * @param local local port
+ * @param remote remote port.
+ *
* @throws TimeoutException in case of timeout on the connection.
* @throws SdbCommandRejectedException if sdb rejects the command
* @throws IOException in case of I/O error on the connection.
*/
- public static void createForward( SmartDevelopmentBridge sdb, Device device, int localPort,
- int remotePort) throws TimeoutException, SdbCommandRejectedException, IOException {
+ public static
+ void
+ createForward(
+ final SmartDevelopmentBridge sdb,
+ final Device device,
+ final int local,
+ final int remote
+ )
+ throws IOException
+ {
SocketChannel sdbChan = null;
try {
@@ -244,11 +238,11 @@ public class SdbHelper {
byte[] request = formSdbRequest(String.format(
"host-serial:%1$s:forward:tcp:%2$d;tcp:%3$d", //$NON-NLS-1$
- device.getSerialNumber(), localPort, remotePort));
+ device.getSerialNumber(), local, remote));
write(sdbChan, request);
- SdbResponse resp = readSdbResponse(sdbChan, false /* readDiagString */);
+ SdbResponse resp = readSdbResponse(sdbChan);
if (resp.okay == false) {
Log.w("create-forward", "Error creating forward: " + resp.message);
throw new SdbCommandRejectedException(resp.message);
@@ -259,17 +253,27 @@ public class SdbHelper {
}
/**
- * Remove a port forwarding between a local and a remote port.
- * @param sdb the socket address to connect to sdb
- * @param device the device on which to remove the port fowarding
- * @param localPort the local port of the forward
- * @param remotePort the remote port.
+ * Remove port forward
+ *
+ * @param sdb sdb
+ * @param device device for removeing port forward
+ * @param local local port
+ * @param remote remote port.
+ *
* @throws TimeoutException in case of timeout on the connection.
* @throws SdbCommandRejectedException if sdb rejects the command
* @throws IOException in case of I/O error on the connection.
*/
- public static void removeForward( SmartDevelopmentBridge sdb, Device device, int localPort,
- int remotePort) throws TimeoutException, SdbCommandRejectedException, IOException {
+ public static
+ void
+ removeForward(
+ final SmartDevelopmentBridge sdb,
+ final Device device,
+ final int local,
+ final int remote
+ )
+ throws TimeoutException, SdbCommandRejectedException, IOException
+ {
SocketChannel sdbChan = null;
try {
@@ -277,11 +281,11 @@ public class SdbHelper {
byte[] request = formSdbRequest(String.format(
"host-serial:%1$s:killforward:tcp:%2$d;tcp:%3$d", //$NON-NLS-1$
- device.getSerialNumber(), localPort, remotePort));
+ device.getSerialNumber(), local, remote));
write(sdbChan, request);
- SdbResponse resp = readSdbResponse(sdbChan, false /* readDiagString */);
+ SdbResponse resp = readSdbResponse(sdbChan);
if (resp.okay == false) {
Log.w("remove-forward", "Error creating forward: " + resp.message);
throw new SdbCommandRejectedException(resp.message);
@@ -295,43 +299,40 @@ public class SdbHelper {
}
/**
- * Converts an sdb reply to a string.
+ * Converts reply bytes as a string.
*/
static String replyToString(byte[] reply) {
- String result;
try {
- result = new String(reply, DEFAULT_ENCODING);
+ return new String(reply, DEFAULT_ENCODING);
} catch (UnsupportedEncodingException uee) {
- uee.printStackTrace(); // not expected
- result = "";
+ Log.e( "Unsupported encoding.", uee );
+ return "";
}
- return result;
}
/**
- * Reads from the socket until the array is filled, or no more data is coming (because
- * the socket closed or the timeout expired).
- * <p/>This uses the default time out value.
+ * Reads from the socket and write data totally
*
- * @param chan the opened socket to read from. It must be in non-blocking
- * mode for timeouts to work
+ * @param chan the opened socket to read from.
* @param data the buffer to store the read data into.
* @throws TimeoutException in case of timeout on the connection.
* @throws IOException in case of I/O error on the connection.
+ *
+ * @see #read(SocketChannel, byte[], int, int)
*/
- static void read(SocketChannel chan, byte[] data) throws TimeoutException, IOException {
+ static void read(
+ final SocketChannel chan,
+ final byte[] data
+ )
+ throws TimeoutException, IOException
+ {
read(chan, data, -1, Preferences.getTimeOut());
}
/**
- * Reads from the socket until the array is filled, the optional length
- * is reached, or no more data is coming (because the socket closed or the
- * timeout expired). After "timeout" milliseconds since the
- * previous successful read, this will return whether or not new data has
- * been found.
+ * Reads from the socket and write data totally until time out
*
- * @param chan the opened socket to read from. It must be in non-blocking
- * mode for timeouts to work
+ * @param chan the opened socket to read from.
* @param data the buffer to store the read data into.
* @param length the length to read or -1 to fill the data buffer completely
* @param timeout The timeout value. A timeout of zero means "wait forever".
@@ -362,10 +363,11 @@ public class SdbHelper {
}
/**
- * Write until all data in "data" is written or the connection fails or times out.
- * <p/>This uses the default time out value.
+ * write {@code data}
+ *
* @param chan the opened socket to write to.
* @param data the buffer to send.
+ *
* @throws TimeoutException in case of timeout on the connection.
* @throws IOException in case of I/O error on the connection.
*/
@@ -374,18 +376,24 @@ public class SdbHelper {
}
/**
- * Write until all data in "data" is written, the optional length is reached,
- * the timeout expires, or the connection fails. Returns "true" if all
- * data was written.
+ * write {@code data} untim time out
+ *
* @param chan the opened socket to write to.
* @param data the buffer to send.
* @param length the length to write or -1 to send the whole buffer.
* @param timeout The timeout value. A timeout of zero means "wait forever".
+ *
* @throws TimeoutException in case of timeout on the connection.
* @throws IOException in case of I/O error on the connection.
*/
- public static void write(SocketChannel chan, byte[] data, int length, int timeout)
- throws TimeoutException, IOException {
+ public static void write(
+ final SocketChannel chan,
+ final byte[] data,
+ final int length,
+ final int timeout
+ )
+ throws TimeoutException, IOException
+ {
ByteBuffer buf = ByteBuffer.wrap(data, 0, length < 0 ? data.length : length );
int numWaits = 0;
@@ -436,7 +444,7 @@ public class SdbHelper {
write(channel, deviceQuery);
- final SdbResponse resp = readSdbResponse(channel, false /* readDiagString */);
+ final SdbResponse resp = readSdbResponse(channel);
if ( !resp.okay )
{
throw new SdbCommandRejectedException( resp.message );
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 7eafdeb92..23bb2f375 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridge.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridge.java
@@ -48,28 +48,35 @@ import org.tizen.sdblib.util.StreamGobbler;
/**
* SmartDevelopmentBridge
- *
- * A connection to the host-side smart development bridge (sdb)
- * <p/>This is the central point to communicate with any devices, emulators, or the applications
- * running on them.
- * <p/><b>{@link #init(boolean)} must be called before anything is done.</b>
+ *
+ * Object to manage device
*
* @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
*/
final public class
SmartDevelopmentBridge
{
+ /**
+ * Logging tag for sdb
+ */
private final static String TAG_SDB = "sdb"; //$NON-NLS-1$
+ /**
+ * Logging tag for sdblib
+ */
private final static String TAG_SDBLIB = "sdblib"; //$NON-NLS-1$
private static InetSocketAddress socketAddr;
+ /**
+ * Singleton instance
+ */
private static SmartDevelopmentBridge instance;
/** Full path to sdb. */
private String mSdbOsLocation = null;
protected Lock lock = new ReentrantLock();
+
private boolean mStarted = false;
private DeviceMonitor deviceMonitor;
@@ -83,29 +90,7 @@ SmartDevelopmentBridge
private static final Object sLock = sBridgeListeners;
/**
- * Initializes the <code>sdb</code> library.
- * <p/>This must be called once <b>before</b> any call to
- * {@link #createBridge(String, boolean)}.
- * <p>The library can be initialized in 2 ways:
- * <ul>
- * <li>Mode 1: <var>clientSupport</var> == <code>true</code>.<br>The library monitors the
- * devices and the applications running on them. It will connect to each application, as a
- * debugger of sort, to be able to interact with them through JDWP packets.</li>
- * <li>Mode 2: <var>clientSupport</var> == <code>false</code>.<br>The library only monitors
- * devices. The applications are left untouched, letting other tools built on
- * <code>sdblib</code> to connect a debugger to them.</li>
- * </ul>
- * <p/><b>Only one tool can run in mode 1 at the same time.</b>
- * <p/>Note that mode 1 does not prevent debugging of applications running on devices. Mode 1
- * lets debuggers connect to <code>sdblib</code> which acts as a proxy between the debuggers and
- * the applications to debug. See {@link Client#getDebuggerListenPort()}.
- * <p/>The preferences of <code>sdblib</code> should also be initialized with whatever default
- * values were changed from the default values.
- * <p/>When the application quits, {@link #terminate()} should be called.
- * @param clientSupport Indicates whether the library should enable the monitoring and
- * interaction with applications running on the devices.
- * @see SmartDevelopmentBridge#createBridge(String, boolean)
- * @see SdbPreferences
+ * Initializes the <code>sdblib</code>.
*/
protected static void init() {
// Determine port and instantiate socket address.
@@ -124,15 +109,6 @@ SmartDevelopmentBridge
}
catch ( final SecurityException ex )
{
- // A security manager has been installed that doesn't allow access to env vars.
- // So an environment variable might have been set, but we can't tell.
- // Let's log a warning and continue with SDB's default port.
- // The issue is that sdb would be started (by the forked process having access
- // to the env vars) on the desired port, but within this process, we can't figure out
- // what that port is. However, a security manager not granting access to env vars
- // but allowing to fork is a rare and interesting configuration, so the right
- // thing seems to be to continue using the default port, as forking is likely to
- // fail later on in the scenario of the security manager.
Log.w(TAG_SDBLIB,
"No access to env variables allowed by current security manager. " //$NON-NLS-1$
+ "If you've set SDB_SERVER_PORT: it's being ignored."); //$NON-NLS-1$
@@ -173,9 +149,14 @@ SmartDevelopmentBridge
* @param forceNewBridge force creation of a new bridge even if one with the same location
* already exists.
* @return a connected bridge.
- * @throws Exception
*/
- public static SmartDevelopmentBridge createBridge(String osLocation, boolean forceNewBridge){
+ public static
+ SmartDevelopmentBridge
+ createBridge(
+ final String osLocation,
+ final boolean forceNewBridge
+ )
+ {
init();
synchronized (sLock) {
if (instance != null) {
@@ -225,10 +206,7 @@ SmartDevelopmentBridge
}
/**
- * Disconnects the current debug bridge, and destroy the object.
- * <p/>This also stops the current sdb host server.
- * <p/>
- * A new object will have to be created with {@link #createBridge(String, boolean)}.
+ * disconnect from sdb
*/
public static void disconnectBridge() {
synchronized (sLock) {
@@ -236,10 +214,6 @@ SmartDevelopmentBridge
instance.stop();
instance = null;
- // because the listeners could remove themselves from the list while processing
- // their event callback, we make a copy of the list and iterate on it instead of
- // the main list.
- // This mostly happens when the application quits.
IDebugBridgeChangeListener[] listenersCopy = sBridgeListeners.toArray(
new IDebugBridgeChangeListener[sBridgeListeners.size()]);
@@ -258,10 +232,9 @@ SmartDevelopmentBridge
}
/**
- * Adds the listener to the collection of listeners who will be notified when a new
- * {@link SmartDevelopmentBridge} is connected, by sending it one of the messages defined
- * in the {@link IDebugBridgeChangeListener} interface.
- * @param listener The listener which should be notified.
+ * Add listener to monitor sdb
+ *
+ * @param listener Thelistener to add
*/
public static void addDebugBridgeChangeListener(IDebugBridgeChangeListener listener) {
synchronized (sLock) {
@@ -281,40 +254,53 @@ SmartDevelopmentBridge
}
/**
- * Removes the listener from the collection of listeners who will be notified when a new
- * {@link SmartDevelopmentBridge} is started.
- * @param listener The listener which should no longer be notified.
+ * Remove listener to monitor sdb
+ *
+ * @param listener The listener to remove
*/
- public static void removeDebugBridgeChangeListener(IDebugBridgeChangeListener listener) {
+ public static
+ void
+ removeDebugBridgeChangeListener(
+ final IDebugBridgeChangeListener listener
+ )
+ {
synchronized (sLock) {
sBridgeListeners.remove(listener);
}
}
/**
- * Adds the listener to the collection of listeners who will be notified when a {@link IDevice}
- * is connected, disconnected, or when its properties or its {@link Client} list changed,
- * by sending it one of the messages defined in the {@link IDeviceChangeListener} interface.
- * @param listener The listener which should be notified.
+ * Add listener to monitor device
+ *
+ * @param listener The listener to add
*/
- public static void addDeviceChangeListener(IDeviceChangeListener listener) {
+ public static void addDeviceChangeListener(
+ final IDeviceChangeListener listener
+ )
+ {
addDeviceChangeListener(listener, false);
}
/**
- * Adds the listener to the collection of listeners who will be notified when a {@link IDevice}
- * is connected, disconnected, or when its properties or its {@link Client} list changed,
- * by sending it one of the messages defined in the {@link IDeviceChangeListener} interface.
+ * Add listener to monitor device.
+ *
+ * Notify initial state if {@code bNotification} is {@code true}
*
- * @param listener The listener which should be notified.
- * @param getPreviousNoti Provides connected device notification which not notified before adding listener.
+ * @param listener The listener to add
+ * @param bNotification flag to notify the initial devices
*/
- public static void addDeviceChangeListener(IDeviceChangeListener listener, boolean getPreviousNoti) {
- IDevice[] devices = SmartDevelopmentBridge.getBridge().getDevices();
+ public static
+ void
+ addDeviceChangeListener(
+ final IDeviceChangeListener listener,
+ final boolean bNotification
+ )
+ {
+ final IDevice[] devices = SmartDevelopmentBridge.getBridge().getDevices();
synchronized (sLock) {
if (sDeviceListeners.contains(listener) == false) {
sDeviceListeners.add(listener);
- if(getPreviousNoti)
+ if(bNotification)
{
for(IDevice device : devices)
{
@@ -329,12 +315,16 @@ SmartDevelopmentBridge
}
/**
- * Removes the listener from the collection of listeners who will be notified when a
- * {@link IDevice} is connected, disconnected, or when its properties or its {@link Client}
- * list changed.
- * @param listener The listener which should no longer be notified.
+ * Removes listener to monitor device.
+ *
+ * @param listener The listener to remove
*/
- public static void removeDeviceChangeListener(IDeviceChangeListener listener) {
+ public static
+ void
+ removeDeviceChangeListener(
+ final IDeviceChangeListener listener
+ )
+ {
synchronized (sLock) {
sDeviceListeners.remove(listener);
}
@@ -342,7 +332,6 @@ SmartDevelopmentBridge
/**
* Returns the devices.
- * @see #hasInitialDeviceList()
*/
public IDevice[] getDevices() {
if (deviceMonitor != null) {
@@ -355,7 +344,10 @@ SmartDevelopmentBridge
/**
* Returns whether the {@link SmartDevelopmentBridge} object is still connected to the sdb daemon.
*/
- public boolean isConnected() {
+ public
+ boolean
+ isConnected()
+ {
if (deviceMonitor != null) {
return deviceMonitor.isMonitoring();
}
@@ -474,32 +466,23 @@ SmartDevelopmentBridge
}
}
+ public
+ IDeviceChangeListener[]
+ getDeviceChangeListeners()
+ {
+ IDeviceChangeListener[] ret = new IDeviceChangeListener[sDeviceListeners.size()];
+ synchronized (sLock) {
+ return sDeviceListeners.toArray( ret );
+ }
+ }
/**
- * Notify the listener of a new {@link IDevice}.
- * <p/>
- * The notification of the listeners is done in a synchronized block. It is important to
- * expect the listeners to potentially access various methods of {@link IDevice} as well as
- * {@link #getDevices()} which use internal locks.
- * <p/>
- * For this reason, any call to this method from a method of {@link DeviceMonitor},
- * {@link IDevice} which is also inside a synchronized block, should first synchronize on
- * the {@link SmartDevelopmentBridge} lock. Access to this lock is done through {@link #getLock()}.
- * @param device the new <code>IDevice</code>.
- * @see #getLock()
+ * Initialize new device
+ *
+ * @param device the new <code>IDevice</code> to initialize
*/
void deviceConnected(IDevice device) {
- // because the listeners could remove themselves from the list while processing
- // their event callback, we make a copy of the list and iterate on it instead of
- // the main list.
- // This mostly happens when the application quits.
- IDeviceChangeListener[] listenersCopy;
- synchronized (sLock) {
- listenersCopy = sDeviceListeners.toArray(
- new IDeviceChangeListener[sDeviceListeners.size()]);
- }
-
// Notify the listeners
- for (IDeviceChangeListener listener : listenersCopy) {
+ for ( final IDeviceChangeListener listener : getDeviceChangeListeners() ) {
// we attempt to catch any exception so that a bad listener doesn't kill our
// thread
try {
@@ -511,31 +494,13 @@ SmartDevelopmentBridge
}
/**
- * Notify the listener of a disconnected {@link IDevice}.
- * <p/>
- * The notification of the listeners is done in a synchronized block. It is important to
- * expect the listeners to potentially access various methods of {@link IDevice} as well as
- * {@link #getDevices()} which use internal locks.
- * <p/>
- * For this reason, any call to this method from a method of {@link DeviceMonitor},
- * {@link IDevice} which is also inside a synchronized block, should first synchronize on
- * the {@link SmartDevelopmentBridge} lock. Access to this lock is done through {@link #getLock()}.
- * @param device the disconnected <code>IDevice</code>.
- * @see #getLock()
+ * Destroy disconnected device
+ *
+ * @param device the disconnected <code>IDevice</code> to destroy
*/
void deviceDisconnected(IDevice device) {
- // because the listeners could remove themselves from the list while processing
- // their event callback, we make a copy of the list and iterate on it instead of
- // the main list.
- // This mostly happens when the application quits.
- IDeviceChangeListener[] listenersCopy;
- synchronized (sLock) {
- listenersCopy = sDeviceListeners.toArray(
- new IDeviceChangeListener[sDeviceListeners.size()]);
- }
-
// Notify the listeners
- for (IDeviceChangeListener listener : listenersCopy) {
+ for (IDeviceChangeListener listener : getDeviceChangeListeners() ) {
// we attempt to catch any exception so that a bad listener doesn't kill our
// thread
try {
@@ -547,31 +512,14 @@ SmartDevelopmentBridge
}
/**
- * Notify the listener of a modified {@link IDevice}.
- * <p/>
- * The notification of the listeners is done in a synchronized block. It is important to
- * expect the listeners to potentially access various methods of {@link IDevice} as well as
- * {@link #getDevices()} which use internal locks.
- * <p/>
- * For this reason, any call to this method from a method of {@link DeviceMonitor},
- * {@link IDevice} which is also inside a synchronized block, should first synchronize on
- * the {@link SmartDevelopmentBridge} lock. Access to this lock is done through {@link #getLock()}.
- * @param device the modified <code>IDevice</code>.
- * @see #getLock()
+ *
+ * Notify the listener modification of {@link IDevice}.
+ *
+ * @param device the modified <code>IDevice</code>
*/
void deviceChanged(IDevice device, int changeMask) {
- // because the listeners could remove themselves from the list while processing
- // their event callback, we make a copy of the list and iterate on it instead of
- // the main list.
- // This mostly happens when the application quits.
- IDeviceChangeListener[] listenersCopy;
- synchronized (sLock) {
- listenersCopy = sDeviceListeners.toArray(
- new IDeviceChangeListener[sDeviceListeners.size()]);
- }
-
// Notify the listeners
- for (IDeviceChangeListener listener : listenersCopy) {
+ for (IDeviceChangeListener listener : getDeviceChangeListeners()) {
// we attempt to catch any exception so that a bad listener doesn't kill our
// thread
try {
@@ -675,14 +623,12 @@ SmartDevelopmentBridge
}
/**
- * Get the stderr/stdout outputs of a process and return when the process is done.
- * Both <b>must</b> be read or the process will block on windows.
+ * Get the stderr outputs
+ *
* @param process The process to get the ouput from
- * @param errorOutput The array to store the stderr output. cannot be null.
- * @param stdOutput The array to store the stdout output. cannot be null.
- * @param displayStdOut If true this will display stdout as well
- * @param waitforReaders if true, this will wait for the reader threads.
- * @return the process return code.
+ *
+ * @return contents of error stream( stderr )
+ *
* @throws InterruptedException
*/
private
@@ -690,7 +636,8 @@ SmartDevelopmentBridge
grabProcessError(
final Process process
)
- throws InterruptedException {
+ throws InterruptedException
+ {
// read the lines as they come. if null is returned, it's
// because the process finished
StreamGobbler errorGobbler = new StreamGobbler( process.getErrorStream() );
@@ -726,10 +673,7 @@ SmartDevelopmentBridge
}
/**
- * Returns the singleton lock used by this class to protect any access to the listener.
- * <p/>
- * This includes adding/removing listeners, but also notifying listeners of new bridges,
- * devices, and clients.
+ * @return singleton lock for listener
*/
static Object getLock() {
return sLock;
@@ -739,6 +683,7 @@ SmartDevelopmentBridge
{
waitforStart( -1 );
}
+
public void waitforStart( long timeout )
{
final long startTime = System.currentTimeMillis();
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridgetConstants.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridgetConstants.java
index 76a37f80e..5671a7127 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridgetConstants.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridgetConstants.java
@@ -55,11 +55,34 @@ SmartDevelopmentBridgetConstants
*/
public static final byte[] ID_OKAY = "OKAY".getBytes();
+ /**
+ * Fail response
+ */
public static final byte[] ID_FAIL = "FAIL".getBytes();
+
+ /**
+ * Recieved response
+ */
public static final byte[] ID_RECV = "RECV".getBytes();
+
+ /**
+ * Data response
+ */
public static final byte[] ID_DATA = "DATA".getBytes();
+
+ /**
+ * Done response
+ */
public static final byte[] ID_DONE = "DONE".getBytes();
+
+ /**
+ * Send response
+ */
public static final byte[] ID_SEND = "SEND".getBytes();
+
+ /**
+ * Quit response
+ */
public static final byte[] ID_QUIT = "QUIT".getBytes();
}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/command/Command.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/command/Command.java
index 13fcbd7cb..980e9f674 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/command/Command.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/command/Command.java
@@ -214,7 +214,7 @@ implements ICommand, ICommandWithArgument, ICommandWithArgument2
byte[] request = SdbHelper.formSdbRequest("shell:" + cmd); //$NON-NLS-1$
SdbHelper.write(channel, request);
- SdbResponse resp = SdbHelper.readSdbResponse(channel, false /* readDiagString */);
+ SdbResponse resp = SdbHelper.readSdbResponse(channel);
if (resp.okay == false) {
Log.e("sdb", "sdb rejected shell command (" + cmd + "): " + resp.message);
throw new SdbCommandRejectedException(resp.message);
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/command/matcher/MultiMatcher.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/command/matcher/MultiMatcher.java
index 441ba5150..73e58f009 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/command/matcher/MultiMatcher.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/command/matcher/MultiMatcher.java
@@ -25,8 +25,6 @@
*/
package org.tizen.sdblib.command.matcher;
-import static org.tizen.sdblib.util.CollectionUtil.concatenate;
-
import java.io.IOException;
import java.util.Collection;
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/exception/SyncException.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/exception/SyncException.java
index 0cfccc4f8..6596a4909 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/exception/SyncException.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/exception/SyncException.java
@@ -27,6 +27,8 @@ package org.tizen.sdblib.exception;
import java.io.IOException;
+import org.tizen.sdblib.service.SyncServiceReturnCode;
+
/**
* <p>
* SyncException
@@ -95,6 +97,32 @@ extends IOException
this.code = code;
}
+ public
+ SyncException(
+ final SyncServiceReturnCode code
+ )
+ {
+ this( code.value() );
+ }
+
+ public
+ SyncException(
+ final SyncServiceReturnCode code,
+ final Throwable cause
+ )
+ {
+ this( code.value(), cause );
+ }
+
+ public
+ SyncException(
+ final SyncServiceReturnCode code,
+ final String message
+ )
+ {
+ this( code.value(), message );
+ }
+
/**
* Return error code
*
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/FileEntryFactory.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/FileEntryFactory.java
index b30292751..4e642e686 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/FileEntryFactory.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/FileEntryFactory.java
@@ -26,7 +26,6 @@
package org.tizen.sdblib.receiver;
import static org.tizen.sdblib.util.CollectionUtil.concatenate;
-import static org.tizen.sdblib.util.ParsingUtil.parseInt;
import static org.tizen.sdblib.util.StringUtil.trimTrailingCharacter;
import java.util.regex.Matcher;
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/CrashReportService.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/CrashReportService.java
index 200e57780..ed6624d11 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/CrashReportService.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/CrashReportService.java
@@ -125,7 +125,7 @@ implements IDeviceChangeListener
byte[] request = SdbHelper.formSdbRequest("cs:");
SdbHelper.write( channel, request );
- SdbResponse resp = SdbHelper.readSdbResponse(channel, false);
+ SdbResponse resp = SdbHelper.readSdbResponse(channel);
if (resp.okay == false) {
Log.e("sdb", "got unhappy response from sdb cs req: " + resp.message);
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryInputStream.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryInputStream.java
index 0a42085b2..638fb4713 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryInputStream.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryInputStream.java
@@ -36,11 +36,11 @@ import static org.tizen.sdblib.SmartDevelopmentBridgetConstants.ID_DONE;
import static org.tizen.sdblib.SmartDevelopmentBridgetConstants.ID_RECV;
import static org.tizen.sdblib.service.FileEntryConstants.REMOTE_PATH_MAX_LENGTH;
import static org.tizen.sdblib.service.FileEntryConstants.SYNC_DATA_MAX;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_BUFFER_OVERRUN;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_CONNECTION_ERROR;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_CONNECTION_TIMEOUT;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_REMOTE_PATH_ENCODING;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_REMOTE_PATH_LENGTH;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_BUFFER_OVERRUN;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_CONNECTION_ERROR;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_CONNECTION_TIMEOUT;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_REMOTE_PATH_ENCODING;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_REMOTE_PATH_LENGTH;
import static org.tizen.sdblib.util.Assert.notNull;
import java.io.IOException;
@@ -53,7 +53,7 @@ import org.tizen.sdblib.SdbResponse;
import org.tizen.sdblib.SmartDevelopmentBridge;
import org.tizen.sdblib.exception.SyncException;
import org.tizen.sdblib.exception.TimeoutException;
-import org.tizen.sdblib.util.ArrayHelper;
+import org.tizen.sdblib.util.ByteUtil;
import org.tizen.sdblib.util.Log;
/**
@@ -121,7 +121,7 @@ extends InputStream
final byte[] array = new byte[8 + path.length];
System.arraycopy( command, 0, array, 0, 4 );
- ArrayHelper.swap32bitsToArray( path.length, array, 4 );
+ ByteUtil.swap32bitsToArray( path.length, array, 4 );
System.arraycopy( path, 0, array, 8, path.length );
return array;
@@ -153,7 +153,7 @@ extends InputStream
write( channel, formSdbRequest("sync:") );
- SdbResponse res = readSdbResponse( channel, false );
+ SdbResponse res = readSdbResponse( channel );
if ( !res.okay )
{
@@ -215,7 +215,7 @@ extends InputStream
// if we're done, we stop
return -1;
}
- length = ArrayHelper.swap32bitFromArray( header, 4 );
+ length = ByteUtil.swap32bitFromArray( header, 4 );
if ( length > SYNC_DATA_MAX )
{
// buffer overrun!
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryOutputStream.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryOutputStream.java
index 584c1749d..61a96b018 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryOutputStream.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryOutputStream.java
@@ -40,11 +40,11 @@ import static org.tizen.sdblib.SmartDevelopmentBridgetConstants.ID_QUIT;
import static org.tizen.sdblib.SmartDevelopmentBridgetConstants.ID_SEND;
import static org.tizen.sdblib.service.FileEntryConstants.REMOTE_PATH_MAX_LENGTH;
import static org.tizen.sdblib.service.FileEntryConstants.SYNC_DATA_MAX;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_CONNECTION_ERROR;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_CONNECTION_TIMEOUT;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_REMOTE_PATH_ENCODING;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_REMOTE_PATH_LENGTH;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_UNKNOWN_ERROR;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_CONNECTION_ERROR;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_CONNECTION_TIMEOUT;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_REMOTE_PATH_ENCODING;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_REMOTE_PATH_LENGTH;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_UNKNOWN_ERROR;
import static org.tizen.sdblib.util.Assert.notNull;
import java.io.IOException;
@@ -57,7 +57,7 @@ import org.tizen.sdblib.SdbResponse;
import org.tizen.sdblib.SmartDevelopmentBridge;
import org.tizen.sdblib.exception.SyncException;
import org.tizen.sdblib.exception.TimeoutException;
-import org.tizen.sdblib.util.ArrayHelper;
+import org.tizen.sdblib.util.ByteUtil;
import org.tizen.sdblib.util.Log;
/**
@@ -123,7 +123,7 @@ extends OutputStream
SdbHelper.write( channel, request );
- SdbResponse resp = readSdbResponse( channel, false );
+ SdbResponse resp = readSdbResponse( channel );
if ( !resp.okay )
{
@@ -199,7 +199,7 @@ extends OutputStream
}
// now send the data to the device
// first write the amount read
- ArrayHelper.swap32bitsToArray( index - 8, buffer, 4 );
+ ByteUtil.swap32bitsToArray( index - 8, buffer, 4 );
// now write it
try
@@ -245,7 +245,7 @@ extends OutputStream
final byte[] array = new byte[8 + path.length + modeContent.length];
System.arraycopy( command, 0, array, 0, 4 );
- ArrayHelper.swap32bitsToArray( path.length + modeContent.length, array, 4 );
+ ByteUtil.swap32bitsToArray( path.length + modeContent.length, array, 4 );
System.arraycopy( path, 0, array, 8, path.length );
System.arraycopy( modeContent, 0, array, 8 + path.length, modeContent.length );
@@ -274,7 +274,7 @@ extends OutputStream
final byte[] array = new byte[8];
System.arraycopy(command, 0, array, 0, 4);
- ArrayHelper.swap32bitsToArray(value, array, 4);
+ ByteUtil.swap32bitsToArray(value, array, 4);
return array;
}
@@ -303,7 +303,7 @@ extends OutputStream
if ( check( result, 0, ID_FAIL, 0, 4 ) )
{
// read some error message...
- int len = ArrayHelper.swap32bitFromArray(result, 4);
+ int len = ByteUtil.swap32bitFromArray(result, 4);
read(channel, buffer, len, timeOut);
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncResult.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncResult.java
index a2883c4c5..907e01ce0 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncResult.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncResult.java
@@ -25,8 +25,8 @@
*/
package org.tizen.sdblib.service;
-import static org.tizen.sdblib.service.SyncServiceConstants.CODE2MESSAGE;
import static org.tizen.sdblib.util.Assert.notNull;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_OK;
/**
* SyncResult
@@ -49,7 +49,8 @@ SyncResult
* @param code the error code;
*/
private static String errorCodeToString(int code) {
- String message = CODE2MESSAGE.get( code );
+
+ String message = SyncServiceReturnCode.getMessage( code );
notNull( message );
return message;
}
@@ -86,7 +87,33 @@ SyncResult
message = errorMessage;
}
}
+
+ public SyncResult()
+ {
+ this( RESULT_OK );
+ }
+ public SyncResult(SyncServiceReturnCode code) {
+ this( code.value() );
+ }
+
+
+ public SyncResult(
+ final SyncServiceReturnCode code,
+ final String message
+ )
+ {
+ this( code.value(), message );
+ }
+
+ SyncResult(
+ final SyncServiceReturnCode code,
+ final Exception e
+ )
+ {
+ this( code.value(), e );
+ }
+
public int getCode() {
return code;
}
@@ -95,4 +122,8 @@ SyncResult
return message;
}
+ public boolean isOk()
+ {
+ return RESULT_OK.value() == getCode();
+ }
}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncService.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncService.java
index 0b5d848fb..6734d1363 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncService.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncService.java
@@ -28,14 +28,13 @@ package org.tizen.sdblib.service;
import static org.tizen.sdblib.service.SyncServiceConstants.MESSAGE_SIZECHECKING;
import static org.tizen.sdblib.service.SyncServiceConstants.MESSAGE_PULL_FILES;
import static org.tizen.sdblib.service.SyncServiceConstants.MESSAGE_PUSH_FILES;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_CANCELED;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_CONNECTION_ERROR;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_FILE_READ_ERROR;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_FILE_WRITE_ERROR;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_NO_DIR_TARGET;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_OK;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_REMOTE_IS_FILE;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_TARGET_IS_FILE;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_CANCELED;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_CONNECTION_ERROR;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_FILE_READ_ERROR;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_FILE_WRITE_ERROR;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_NO_DIR_TARGET;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_REMOTE_IS_FILE;
+import static org.tizen.sdblib.service.SyncServiceReturnCode.RESULT_TARGET_IS_FILE;
import static org.tizen.sdblib.util.Assert.notNull;
import static org.tizen.sdblib.util.FileEntryUtil.getTotalSize;
import static org.tizen.sdblib.util.FilenameUtil.addTailingPath;
@@ -151,12 +150,11 @@ implements Closeable
return pull( entries, localPath, null );
}
/**
- * Pulls file(s) or folder(s).
- * @param entries the remote item(s) to pull
- * @param localPath The local destination. If the entries count is > 1 or
- * if the unique entry is a folder, this should be a folder.
- * @param monitor The progress monitor. Cannot be null.
- * @return a {@link SyncResult} object with a code and an optional message.
+ * Get and write files
+ * @param entries {@link FileEntry} for remote
+ * @param destination local path to be written
+ * @param monitor {@link ISyncProgressMonitor}
+ * @return result for processing
*
* @see #pull(FileEntry[], String, ISyncProgressMonitor, int)
*/
@@ -173,18 +171,20 @@ implements Closeable
}
/**
- * Pulls file(s) or folder(s).
- * @param entries the remote item(s) to pull
- * @param localPath The local destination. If the entries count is > 1 or
- * if the unique entry is a folder, this should be a folder.
- * @param monitor The progress monitor. Cannot be null.
- * @param time interval while pulling the files
- * @return a {@link SyncResult} object with a code and an optional message.
+ * Get and write files
+ * @param entries {@link FileEntry} for remote
+ * @param destination local path to be written
+ * @param monitor {@link ISyncProgressMonitor}
+ * @param timeOut time for waiting
+ * @return result for processing
+ *
+ * @see #doPull(FileEntry[], String, ISyncProgressMonitor, int)
*/
- public SyncResult
+ public
+ SyncResult
pull(
final FileEntry[] entries,
- final String localPath,
+ final String destination,
ISyncProgressMonitor monitor,
final int timeOut
)
@@ -192,7 +192,7 @@ implements Closeable
monitor = nvl( monitor, NullSyncProgressMonitor.getInstance() );
// first we check the destination is a directory and exists
- final File f = new File( localPath );
+ final File f = new File( destination );
if ( !f.exists() )
{
return new SyncResult(RESULT_NO_DIR_TARGET);
@@ -215,7 +215,7 @@ implements Closeable
// start the monitor
monitor.start(total);
- result= doPull(entries, localPath, monitor, timeOut);
+ result= doPull(entries, destination, monitor, timeOut);
}
catch ( final InterruptedException e )
{
@@ -229,10 +229,21 @@ implements Closeable
return result;
}
- public SyncResult
+ /**
+ * Get and write files
+ * @param entries {@link FileEntry} for remote
+ * @param destination local path to be written
+ * @param monitor {@link ISyncProgressMonitor}
+ * @param timeOut time for waiting
+ * @return result for processing
+ *
+ * @see #doPull(FileEntry, OutputStream, ISyncProgressMonitor, int)
+ */
+ public
+ SyncResult
doPull(
final FileEntry[] entries,
- final String localPath,
+ final String destination,
ISyncProgressMonitor monitor,
final int timeOut
)
@@ -242,7 +253,7 @@ implements Closeable
try {
for ( final FileEntry entry : entries )
{
- final String path = addTailingPath( localPath, entry.getName() );
+ final String path = addTailingPath( destination, entry.getName() );
if ( entry.isDirectory() )
{
new File( path ).mkdir();
@@ -259,7 +270,7 @@ implements Closeable
{
fileOut = new FileOutputStream( path );
SyncResult result = doPull( entry, fileOut, monitor, timeOut );
- if ( RESULT_OK != result.getCode() )
+ if ( !result.isOk() )
{
return result;
}
@@ -271,7 +282,7 @@ implements Closeable
}
}
- return new SyncResult( RESULT_OK );
+ return new SyncResult();
}
catch ( final IOException e )
{
@@ -280,12 +291,12 @@ implements Closeable
}
/**
- * Pulls a remote file
- * @param remote the remote file (length max is 1024)
- * @param out stream to write
- * @param monitor the monitor. The monitor must be started already.
- * @param timeOut value while pulling the file
- * @return a {@link SyncResult} object with a code and an optional message.
+ * Get and write a file
+ * @param remote {@link FileEntry} for remote
+ * @param out stream to be written
+ * @param monitor {@link ISyncProgressMonitor}
+ * @param timeOut time for waiting
+ * @return result for processing
*/
public
SyncResult
@@ -322,7 +333,7 @@ implements Closeable
monitor.advance( nBytes );
}
- return new SyncResult( RESULT_OK );
+ return new SyncResult();
}
catch ( final SyncException e )
{
@@ -525,7 +536,7 @@ implements Closeable
{
SyncResult result = doPush( f.listFiles(), remoteFile, monitor, timeOut);
- if (result.getCode() != RESULT_OK)
+ if ( !result.isOk() )
{
return result;
}
@@ -536,7 +547,8 @@ implements Closeable
try
{
SyncResult result = doPush( fileIn, remoteFile, monitor, timeOut);
- if (result.getCode() != RESULT_OK) {
+ if ( !result.isOk() )
+ {
return result;
}
}
@@ -547,7 +559,7 @@ implements Closeable
}
}
- return new SyncResult(RESULT_OK);
+ return new SyncResult();
} catch ( final IOException e )
{
@@ -636,7 +648,7 @@ implements Closeable
size += nBytes;
monitor.advance( nBytes );
}
- return new SyncResult( RESULT_OK );
+ return new SyncResult();
}
catch ( final SyncException e )
{
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncServiceConstants.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncServiceConstants.java
index cbb45dd2a..09c093098 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncServiceConstants.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncServiceConstants.java
@@ -25,78 +25,20 @@
*/
package org.tizen.sdblib.service;
-import java.util.Map;
-import org.tizen.sdblib.util.MapUtil;
-public class SyncServiceConstants
+/**
+ * SyncServiceConstants
+ * <p/>
+ * Constants for {@link SyncService}
+ *
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
+ */
+public class
+SyncServiceConstants
{
static final String MESSAGE_SIZECHECKING = "File size checking: it can take some time.";
static final String MESSAGE_PULL_FILES = "Pulling file(s) from the device";
static final String MESSAGE_PUSH_FILES = "Pushing file(s) to the device";
- /** Result code for transfer success. */
- public static final int RESULT_OK = 0;
- /** Result code for canceled transfer */
- public static final int RESULT_CANCELED = 1;
- /** Result code for unknown error */
- public static final int RESULT_UNKNOWN_ERROR = 2;
- /** Result code for network connection error */
- public static final int RESULT_CONNECTION_ERROR = 3;
- /** Result code for unknown remote object during a pull */
- public static final int RESULT_NO_REMOTE_OBJECT = 4;
- /** Result code when attempting to pull multiple files into a file */
- public static final int RESULT_TARGET_IS_FILE = 5;
- /** Result code when attempting to pull multiple into a directory that does not exist. */
- public static final int RESULT_NO_DIR_TARGET = 6;
- /** Result code for wrong encoding on the remote path. */
- public static final int RESULT_REMOTE_PATH_ENCODING = 7;
- /** Result code for remote path that is too long. */
- public static final int RESULT_REMOTE_PATH_LENGTH = 8;
- /** Result code for error while writing local file. */
- public static final int RESULT_FILE_WRITE_ERROR = 9;
- /** Result code for error while reading local file. */
- public static final int RESULT_FILE_READ_ERROR = 10;
- /** Result code for attempting to push a file that does not exist. */
- public static final int RESULT_NO_LOCAL_FILE = 11;
- /** Result code for attempting to push a directory. */
- public static final int RESULT_LOCAL_IS_DIRECTORY = 12;
- /** Result code for when the target path of a multi file push is a file. */
- public static final int RESULT_REMOTE_IS_FILE = 13;
- /** Result code for receiving too much data from the remove device at once */
- public static final int RESULT_BUFFER_OVERRUN = 14;
- /** Result code for network connection timeout */
- public static final int RESULT_CONNECTION_TIMEOUT = 15;
- /** Result code for file exist */
- public static final int RESULT_FILE_EXIST = 16;
- /** Result code for fail delete file */
- public static final int RESULT_FAIL_DELETE_FILE = 17;
- /** Result code for fail delete file */
- public static final int RESULT_FAIL_CREATE_FILE = 18;
-
- /**
- * Error code - messagbe map
- */
- public static final Map<Integer, String> CODE2MESSAGE = MapUtil.asMap( new Object[][] {
- new Object[] { RESULT_OK, "Success." },
- new Object[] { RESULT_CANCELED, "Transfer canceled by the user." },
- new Object[] { RESULT_UNKNOWN_ERROR, "Unknown Error." },
- new Object[] { RESULT_CONNECTION_ERROR, "sdb Connection Error." },
- new Object[] { RESULT_NO_REMOTE_OBJECT, "Remote object doesn't exist!" },
- new Object[] { RESULT_TARGET_IS_FILE, "Target object is a file." },
- new Object[] { RESULT_NO_DIR_TARGET, "Target directory doesn't exist." },
- new Object[] { RESULT_REMOTE_PATH_ENCODING, "Remote Path encoding is not supported." },
- new Object[] { RESULT_REMOTE_PATH_LENGTH, "Remove path is too long." },
- new Object[] { RESULT_FILE_WRITE_ERROR, "Writing local file failed!" },
- new Object[] { RESULT_FILE_READ_ERROR, "Reading local file failed!" },
- new Object[] { RESULT_NO_LOCAL_FILE, "Local file doesn't exist." },
- new Object[] { RESULT_LOCAL_IS_DIRECTORY, "Local path is a directory." },
- new Object[] { RESULT_REMOTE_IS_FILE, "Remote path is a file." },
- new Object[] { RESULT_BUFFER_OVERRUN, "Receiving too much data." },
- new Object[] { RESULT_CONNECTION_TIMEOUT, "timeout" },
- new Object[] { RESULT_FILE_EXIST, "File exists." },
- new Object[] { RESULT_FAIL_DELETE_FILE, "Fail delete file." },
- new Object[] { RESULT_FAIL_CREATE_FILE, "Fail create file." },
-
- } );
}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncServiceReturnCode.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncServiceReturnCode.java
new file mode 100644
index 000000000..0277fbde5
--- /dev/null
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncServiceReturnCode.java
@@ -0,0 +1,72 @@
+package org.tizen.sdblib.service;
+
+import java.util.Map;
+
+import org.tizen.sdblib.util.MapUtil;
+
+public enum
+SyncServiceReturnCode
+{
+ RESULT_OK(0),
+ RESULT_CANCELED(1),
+ RESULT_UNKNOWN_ERROR(2),
+ RESULT_CONNECTION_ERROR(3),
+ RESULT_NO_REMOTE_OBJECT(4),
+ RESULT_TARGET_IS_FILE(5),
+ RESULT_NO_DIR_TARGET(6),
+ RESULT_REMOTE_PATH_ENCODING(7),
+ RESULT_REMOTE_PATH_LENGTH(8),
+ RESULT_FILE_WRITE_ERROR(9),
+ RESULT_FILE_READ_ERROR(10),
+ RESULT_NO_LOCAL_FILE(11),
+ RESULT_LOCAL_IS_DIRECTORY(12),
+ RESULT_REMOTE_IS_FILE(13),
+ RESULT_BUFFER_OVERRUN(14),
+ RESULT_CONNECTION_TIMEOUT(15),
+ RESULT_FILE_EXIST(16),
+ RESULT_FAIL_DELETE_FILE(17),
+ RESULT_FAIL_CREATE_FILE(18);
+
+ private int value;
+ private SyncServiceReturnCode(int value) {
+ this.value = value;
+ }
+
+ public int value()
+ {
+ return value;
+ }
+
+
+ /**
+ * Error code - messagbe map
+ */
+ protected static final Map<Integer, String> CODE2MESSAGE = MapUtil.asMap( new Object[][] {
+ new Object[] { RESULT_OK, "Success." },
+ new Object[] { RESULT_CANCELED, "Transfer canceled by the user." },
+ new Object[] { RESULT_UNKNOWN_ERROR, "Unknown Error." },
+ new Object[] { RESULT_CONNECTION_ERROR, "sdb Connection Error." },
+ new Object[] { RESULT_NO_REMOTE_OBJECT, "Remote object doesn't exist!" },
+ new Object[] { RESULT_TARGET_IS_FILE, "Target object is a file." },
+ new Object[] { RESULT_NO_DIR_TARGET, "Target directory doesn't exist." },
+ new Object[] { RESULT_REMOTE_PATH_ENCODING, "Remote Path encoding is not supported." },
+ new Object[] { RESULT_REMOTE_PATH_LENGTH, "Remove path is too long." },
+ new Object[] { RESULT_FILE_WRITE_ERROR, "Writing local file failed!" },
+ new Object[] { RESULT_FILE_READ_ERROR, "Reading local file failed!" },
+ new Object[] { RESULT_NO_LOCAL_FILE, "Local file doesn't exist." },
+ new Object[] { RESULT_LOCAL_IS_DIRECTORY, "Local path is a directory." },
+ new Object[] { RESULT_REMOTE_IS_FILE, "Remote path is a file." },
+ new Object[] { RESULT_BUFFER_OVERRUN, "Receiving too much data." },
+ new Object[] { RESULT_CONNECTION_TIMEOUT, "timeout" },
+ new Object[] { RESULT_FILE_EXIST, "File exists." },
+ new Object[] { RESULT_FAIL_DELETE_FILE, "Fail delete file." },
+ new Object[] { RESULT_FAIL_CREATE_FILE, "Fail create file." },
+
+ } );
+
+ public static
+ String getMessage( int val )
+ {
+ return CODE2MESSAGE.get( val );
+ }
+}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/util/ArrayHelper.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/util/ArrayHelper.java
index 5bd62bb07..4e7705f92 100755
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/util/ArrayHelper.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/util/ArrayHelper.java
@@ -26,7 +26,9 @@
package org.tizen.sdblib.util;
/**
- * Utility class providing array to int/long conversion for data received from devices through sdb.
+ * ArrayHelper
+ *
+ * Helper for array
*
* @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
*/
@@ -37,11 +39,11 @@ ArrayHelper
protected ArrayHelper() {}
/**
- * Swaps an unsigned value around, and puts the result in an array that can be sent to a device.
+ * convert integer to byte[] and write to byte[]
+ *
* @param value The value to swap.
- * @param dest the destination array
- * @param offset the offset in the array where to put the swapped value.
- * Array length must be at least offset + 4
+ * @param dest byte[] to write to
+ * @param offset {@code dest}'s offset
*/
public static
void
@@ -58,10 +60,12 @@ ArrayHelper
}
/**
- * Reads a signed 32 bit integer from an array coming from a device.
- * @param value the array containing the int
- * @param offset the offset in the array at which the int starts
- * @return the integer read from the array
+ * Convert byte[] to integer and return it
+ *
+ * @param value byte[] to convert
+ * @param offset {@code value}'s offset
+ *
+ * @return integer to be converted
*/
public static
int
@@ -75,47 +79,4 @@ ArrayHelper
| ((((int)value[offset + 2]) & 0x000000FF) << 16)
| ((((int)value[offset + 3]) & 0x000000FF) << 24);
}
-
- /**
- * Reads an unsigned 16 bit integer from an array coming from a device,
- * and returns it as an 'int'
- * @param value the array containing the 16 bit int (2 byte).
- * @param offset the offset in the array at which the int starts
- * Array length must be at least offset + 2
- * @return the integer read from the array.
- */
- public static
- int
- swapU16bitFromArray(
- final byte[] value,
- final int offset
- )
- {
- return (((int)value[offset]) & 0x000000FF )
- | ((((int)value[offset + 1]) & 0x000000FF) << 8);
- }
-
- /**
- * Reads a signed 64 bit integer from an array coming from a device.
- * @param value the array containing the int
- * @param offset the offset in the array at which the int starts
- * Array length must be at least offset + 8
- * @return the integer read from the array
- */
- public static
- long
- swap64bitFromArray(
- final byte[] value,
- final int offset
- )
- {
- return (((long)value[offset]) & 0x00000000000000FFL)
- | ((((long)value[offset + 1]) & 0x00000000000000FFL) << 8)
- | ((((long)value[offset + 2]) & 0x00000000000000FFL) << 16)
- | ((((long)value[offset + 3]) & 0x00000000000000FFL) << 24)
- | ((((long)value[offset + 4]) & 0x00000000000000FFL) << 32)
- | ((((long)value[offset + 5]) & 0x00000000000000FFL) << 40)
- | ((((long)value[offset + 6]) & 0x00000000000000FFL) << 48)
- | ((((long)value[offset + 7]) & 0x00000000000000FFL) << 56);
- }
}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/util/ByteUtil.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/util/ByteUtil.java
new file mode 100755
index 000000000..7fdcd05ee
--- /dev/null
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/util/ByteUtil.java
@@ -0,0 +1,122 @@
+/*
+ * sdblib
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Kangho Kim <kh5325.kim@samsung.com>
+ * BonYong Lee <bonyong.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+package org.tizen.sdblib.util;
+
+/**
+ * ByteUtil
+ * Helper for byte using communication
+ *
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
+ */
+public final class
+ByteUtil
+{
+
+ protected ByteUtil() {}
+
+ /**
+ * Swaps an unsigned value around, and puts the result in an array that can be sent to a device.
+ * @param value The value to swap.
+ * @param dest the destination array
+ * @param offset the offset in the array where to put the swapped value.
+ * Array length must be at least offset + 4
+ */
+ public static
+ void
+ swap32bitsToArray(
+ final int value,
+ final byte[] dest,
+ final int offset
+ )
+ {
+ dest[offset] = (byte)(value & 0x000000FF);
+ dest[offset + 1] = (byte)((value & 0x0000FF00) >> 8);
+ dest[offset + 2] = (byte)((value & 0x00FF0000) >> 16);
+ dest[offset + 3] = (byte)((value & 0xFF000000) >> 24);
+ }
+
+ /**
+ * Reads a signed 32 bit integer from an array coming from a device.
+ * @param value the array containing the int
+ * @param offset the offset in the array at which the int starts
+ * @return the integer read from the array
+ */
+ public static
+ int
+ swap32bitFromArray(
+ final byte[] value,
+ final int offset
+ )
+ {
+ return (((int)value[offset]) & 0x000000FF)
+ | ((((int)value[offset + 1]) & 0x000000FF) << 8)
+ | ((((int)value[offset + 2]) & 0x000000FF) << 16)
+ | ((((int)value[offset + 3]) & 0x000000FF) << 24);
+ }
+
+ /**
+ * Reads an unsigned 16 bit integer from an array coming from a device,
+ * and returns it as an 'int'
+ * @param value the array containing the 16 bit int (2 byte).
+ * @param offset the offset in the array at which the int starts
+ * Array length must be at least offset + 2
+ * @return the integer read from the array.
+ */
+ public static
+ int
+ swapU16bitFromArray(
+ final byte[] value,
+ final int offset
+ )
+ {
+ return (((int)value[offset]) & 0x000000FF )
+ | ((((int)value[offset + 1]) & 0x000000FF) << 8);
+ }
+
+ /**
+ * Reads a signed 64 bit integer from an array coming from a device.
+ * @param value the array containing the int
+ * @param offset the offset in the array at which the int starts
+ * Array length must be at least offset + 8
+ * @return the integer read from the array
+ */
+ public static
+ long
+ swap64bitFromArray(
+ final byte[] value,
+ final int offset
+ )
+ {
+ return (((long)value[offset]) & 0x00000000000000FFL)
+ | ((((long)value[offset + 1]) & 0x00000000000000FFL) << 8)
+ | ((((long)value[offset + 2]) & 0x00000000000000FFL) << 16)
+ | ((((long)value[offset + 3]) & 0x00000000000000FFL) << 24)
+ | ((((long)value[offset + 4]) & 0x00000000000000FFL) << 32)
+ | ((((long)value[offset + 5]) & 0x00000000000000FFL) << 40)
+ | ((((long)value[offset + 6]) & 0x00000000000000FFL) << 48)
+ | ((((long)value[offset + 7]) & 0x00000000000000FFL) << 56);
+ }
+}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/util/DeviceUtil.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/util/DeviceUtil.java
index b9c5bf41f..bb9c1b919 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/util/DeviceUtil.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/util/DeviceUtil.java
@@ -26,7 +26,6 @@
package org.tizen.sdblib.util;
import static org.tizen.sdblib.DeviceConstants.LOG_TAG;
-import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_OK;
import java.io.IOException;
@@ -108,7 +107,7 @@ DeviceUtil
final SyncResult result = sync.push(localPath, device.getFileEntry( remoteFilePath ) );
- if (result.getCode() != RESULT_OK)
+ if (!result.isOk())
{
throw new IOException(String.format("Unable to upload file: %1$s", result.getMessage()));
}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/util/LogLevel.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/util/LogLevel.java
index d39ff6cf5..c679a18f3 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/util/LogLevel.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/util/LogLevel.java
@@ -105,52 +105,42 @@ LogLevel
}
/**
- * Returns the {@link LogLevel} enum matching the specified letter.
- * @param letter the letter matching a <code>LogLevel</code> enum
- * @return a <code>LogLevel</code> object or <code>null</code> if no match were found.
+ * Returns the {@link LogLevel} enum matching the specified string
+ *
+ * @param val string to present log level
+ * @return LogLevel for {@code val}
*/
- public static LogLevel getByLetter(char letter) {
- for (LogLevel mode : values()) {
- if (mode.letter == letter) {
- return mode;
+ public static LogLevel getByLetter(String val) {
+ if (val.length() > 0) {
+ char ch = val.charAt( 0 );
+ for (LogLevel mode : values()) {
+ if (mode.letter == ch) {
+ return mode;
+ }
}
- }
-
- return null;
- }
- /**
- * Returns the {@link LogLevel} enum matching the specified letter.
- * <p/>
- * The letter is passed as a {@link String} argument, but only the first character
- * is used.
- * @param letter the letter matching a <code>LogLevel</code> enum
- * @return a <code>LogLevel</code> object or <code>null</code> if no match were found.
- */
- public static LogLevel getByLetterString(String letter) {
- if (letter.length() > 0) {
- return getByLetter(letter.charAt(0));
+ return null;
}
return null;
}
/**
- * Returns the letter identifying the priority of the {@link LogLevel}.
+ * @return the letter for {@link LogLevel}
*/
public char getLetter() {
return letter;
}
/**
- * Returns the numerical value of the priority.
+ * @return priority to order
*/
public int getPriority() {
return priority;
}
/**
- * Returns a non translated string representing the LogLevel.
+ * @return name of {@link LogLevel}
*/
public String getName() {
return name;