Allow sdb to listen on both usb and TCP. 46/18546/3 accepted/tizen_ivi_panda accepted/tizen/generic/20140331.081744 accepted/tizen/ivi/20140328.192816 accepted/tizen/ivi/panda/20140328.181242 accepted/tizen/ivi/release/20140404.171232 submit/tizen/20140328.080409 submit/tizen_ivi_release/20140404.170142
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Mon, 24 Mar 2014 12:41:23 +0000 (13:41 +0100)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Thu, 27 Mar 2014 11:18:24 +0000 (12:18 +0100)
Fix semantic of --listen option to allow run sdb
with TCP backend on real device.

Add systemd target to allow run sdb with tcp backend,

Change-Id: I3499ee1e90539961629ad6a5a763b99c2fb7bb6b
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
packaging/sdbd.spec
packaging/sdbd_tcp.service [new file with mode: 0644]
src/commandline_sdbd.c
src/sdb.c
test/test_commandline_sdbd.c

index 93b4687fc1a2d7f872f7c070aff36b7ce270353e..a3f00d17b2b916ef5f9775ee3d4b93ebda20d381 100644 (file)
@@ -9,6 +9,7 @@ Source0:    %{name}-%{version}.tar.gz
 Source1001:    sdbd_device.service
 Source1002:    sdbd_emulator.service
 Source1003:    %{name}.manifest
+Source1004:    sdbd_tcp.service
 
 BuildRequires: capi-system-info-devel >= 0.2.0
 BuildRequires: cmake >= 2.8.3
@@ -37,6 +38,7 @@ mkdir -p %{buildroot}/%{_libdir}/systemd/system/emulator.target.wants
 ln -s %{_libdir}/systemd/system/sdbd.service %{buildroot}/%{_libdir}/systemd/system/emulator.target.wants/
 %else
 install -m 0644 %SOURCE1001 %{buildroot}%{_libdir}/systemd/system/sdbd.service
+install -m 0644 %SOURCE1004 %{buildroot}%{_libdir}/systemd/system/sdbd_tcp.service
 %endif
 
 mkdir -p %{buildroot}%{_prefix}/sbin
@@ -52,6 +54,8 @@ install -m 755 script/sdk_launch %{buildroot}%{_prefix}/sbin/
 %{_libdir}/systemd/system/sdbd.service
 %if 0%{?simulator}
 %{_libdir}/systemd/system/emulator.target.wants/sdbd.service
+%else
+%{_libdir}/systemd/system/sdbd_tcp.service
 %endif
 
 %changelog
diff --git a/packaging/sdbd_tcp.service b/packaging/sdbd_tcp.service
new file mode 100644 (file)
index 0000000..3818b6d
--- /dev/null
@@ -0,0 +1,10 @@
+[Unit]
+Description=sdbd
+After=default.target
+
+[Service]
+Type=forking
+Environment=DISPLAY=:0
+PIDFile=/tmp/.sdbd.pid
+RemainAfterExit=yes
+ExecStart=/usr/sbin/sdbd --listen=26101
index f1c3f5540ebe0f15d0104525e3fb5c4f7e314da7..ec16a0db929f0126f5c612cd4818d1f207db859d 100644 (file)
@@ -63,6 +63,12 @@ int parse_sdbd_commandline(SdbdCommandlineArgs *sdbd_args, int argc, char *argv[
                        if (split_retval != SDBD_COMMANDLINE_SUCCESS) {
                                return split_retval;
                        }
+                       /* if we are on emulator we listen using local transport
+                        * so we should set port to default value but this can
+                        * be overwritten by command line options */
+                       if (sdbd_args->sdbd_port < 0) {
+                               sdbd_args->sdbd_port = DEFAULT_SDB_LOCAL_TRANSPORT_PORT;
+                       }
                        break;
                case ARG_S_SENSORS:
                        split_retval = split_host_port(optarg,
@@ -109,7 +115,8 @@ void apply_sdbd_commandline_defaults(SdbdCommandlineArgs *sdbd_args) {
        sdbd_args->sdb.host = strdup(QEMU_FORWARD_IP);
        sdbd_args->sdb.port = DEFAULT_SDB_PORT;
 
-       sdbd_args->sdbd_port = DEFAULT_SDB_LOCAL_TRANSPORT_PORT;
+       // by default don't listen on local transport
+       sdbd_args->sdbd_port = -1;
 }
 
 
index 90f4cfa2ea5214f2d01403b8334c7c95af2d8bf0..0ab561a53242d0a619f6ee22c6deeb62923e3136 100644 (file)
--- a/src/sdb.c
+++ b/src/sdb.c
@@ -1232,11 +1232,12 @@ int sdb_main(int is_daemon, int server_port)
     if (!is_emulator()) {
         // listen on USB
         usb_init();
-        // listen on tcp
-        //local_init(DEFAULT_SDB_LOCAL_TRANSPORT_PORT);
-    } else {
-        // listen on default port
-        local_init(DEFAULT_SDB_LOCAL_TRANSPORT_PORT);
+    }
+
+    /* by default don't listen on local transport but
+     * listen if suitable command line argument has been provided */
+    if (sdbd_commandline_args.sdbd_port >= 0) {
+        local_init(sdbd_commandline_args.sdbd_port);
     }
 
 #if 0 /* tizen specific */
index 4dd67e849bcc94ac843fc7118051f5b7d6a4f80a..dc0234560ddfe7c52146e17c3e4acb56276f4246 100644 (file)
@@ -103,6 +103,44 @@ START_TEST(test_all_opts) {
 
 } END_TEST
 
+START_TEST(test_emul_default_tcp_port) {
+        char *test_argv[] = {
+                        "./test",
+                        "--emulator=tizen:101",
+        };
+
+        SdbdCommandlineArgs sdbd_args = {0};
+
+        apply_sdbd_commandline_defaults(&sdbd_args);
+        int parse_res = parse_sdbd_commandline(&sdbd_args, array_size(test_argv), test_argv);
+
+        if (parse_res != SDBD_COMMANDLINE_SUCCESS) {
+                ck_abort_msg("parsing commandline failed");
+                return;
+        }
+
+        ck_assert_hostport_eq(&sdbd_args.emulator, "tizen", 101);
+       ck_assert_int_eq(sdbd_args.sdbd_port, DEFAULT_SDB_LOCAL_TRANSPORT_PORT);
+} END_TEST
+
+START_TEST(test_tcp_port) {
+        char *test_argv[] = {
+                        "./test",
+                       "--listen-port=101",
+        };
+
+        SdbdCommandlineArgs sdbd_args = {0};
+
+        apply_sdbd_commandline_defaults(&sdbd_args);
+        int parse_res = parse_sdbd_commandline(&sdbd_args, array_size(test_argv), test_argv);
+
+        if (parse_res != SDBD_COMMANDLINE_SUCCESS) {
+                ck_abort_msg("parsing commandline failed");
+                return;
+        }
+
+        ck_assert_int_eq(sdbd_args.sdbd_port, 101);
+} END_TEST
 
 START_TEST(test_empty) {
        char *test_argv[] = {
@@ -181,7 +219,7 @@ START_TEST(test_default_args) {
        ck_assert_hostport_eq(&sdbd_args.emulator, NULL, 0);
        ck_assert_hostport_eq(&sdbd_args.sensors, QEMU_FORWARD_IP, DEFAULT_SENSORS_LOCAL_TRANSPORT_PORT);
        ck_assert_hostport_eq(&sdbd_args.sdb, QEMU_FORWARD_IP, DEFAULT_SDB_PORT);
-       ck_assert_int_eq(sdbd_args.sdbd_port, DEFAULT_SDB_LOCAL_TRANSPORT_PORT);
+       ck_assert_int_eq(sdbd_args.sdbd_port, -1);
 } END_TEST