Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4602adbc authored by Josh Gao's avatar Josh Gao
Browse files

adb: add sysdeps/chrono.h for chrono literals on Win32.

Bug: http://b/32878766
Test: mma
Change-Id: Iaa89d4eadf07e63d6d7205057435a6c7fb5d4ec5
parent 59826dde
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -28,7 +28,6 @@
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>


#include <chrono>
#include <string>
#include <string>
#include <thread>
#include <thread>
#include <vector>
#include <vector>
@@ -40,6 +39,7 @@
#include "adb_io.h"
#include "adb_io.h"
#include "adb_utils.h"
#include "adb_utils.h"
#include "socket_spec.h"
#include "socket_spec.h"
#include "sysdeps/chrono.h"


static TransportType __adb_transport = kTransportAny;
static TransportType __adb_transport = kTransportAny;
static const char* __adb_serial = NULL;
static const char* __adb_serial = NULL;
@@ -191,7 +191,7 @@ int adb_connect(const std::string& service, std::string* error) {
            fprintf(stdout,"* daemon started successfully *\n");
            fprintf(stdout,"* daemon started successfully *\n");
        }
        }
        // Give the server some time to start properly and detect devices.
        // Give the server some time to start properly and detect devices.
        std::this_thread::sleep_for(std::chrono::seconds(3));
        std::this_thread::sleep_for(3s);
        // fall through to _adb_connect
        // fall through to _adb_connect
    } else {
    } else {
        // If a server is already running, check its version matches.
        // If a server is already running, check its version matches.
@@ -236,7 +236,7 @@ int adb_connect(const std::string& service, std::string* error) {
            }
            }


            /* XXX can we better detect its death? */
            /* XXX can we better detect its death? */
            std::this_thread::sleep_for(std::chrono::seconds(2));
            std::this_thread::sleep_for(2s);
            goto start_server;
            goto start_server;
        }
        }
    }
    }
+0 −1
Original line number Original line Diff line number Diff line
@@ -20,7 +20,6 @@


#include <unistd.h>
#include <unistd.h>


#include <chrono>
#include <thread>
#include <thread>


#include <android-base/stringprintf.h>
#include <android-base/stringprintf.h>
+2 −2
Original line number Original line Diff line number Diff line
@@ -31,7 +31,6 @@
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>


#include <chrono>
#include <memory>
#include <memory>
#include <string>
#include <string>
#include <thread>
#include <thread>
@@ -61,6 +60,7 @@
#include "file_sync_service.h"
#include "file_sync_service.h"
#include "services.h"
#include "services.h"
#include "shell_service.h"
#include "shell_service.h"
#include "sysdeps/chrono.h"


static int install_app(TransportType t, const char* serial, int argc, const char** argv);
static int install_app(TransportType t, const char* serial, int argc, const char** argv);
static int install_multiple_app(TransportType t, const char* serial, int argc, const char** argv);
static int install_multiple_app(TransportType t, const char* serial, int argc, const char** argv);
@@ -1082,7 +1082,7 @@ static bool adb_root(const char* command) {


    // Give adbd some time to kill itself and come back up.
    // Give adbd some time to kill itself and come back up.
    // We can't use wait-for-device because devices (e.g. adb over network) might not come back.
    // We can't use wait-for-device because devices (e.g. adb over network) might not come back.
    std::this_thread::sleep_for(std::chrono::seconds(3));
    std::this_thread::sleep_for(3s);
    return true;
    return true;
}
}


+3 −3
Original line number Original line Diff line number Diff line
@@ -19,7 +19,6 @@
#include <gtest/gtest.h>
#include <gtest/gtest.h>


#include <array>
#include <array>
#include <chrono>
#include <limits>
#include <limits>
#include <queue>
#include <queue>
#include <string>
#include <string>
@@ -33,6 +32,7 @@
#include "fdevent_test.h"
#include "fdevent_test.h"
#include "socket.h"
#include "socket.h"
#include "sysdeps.h"
#include "sysdeps.h"
#include "sysdeps/chrono.h"


struct ThreadArg {
struct ThreadArg {
    int first_read_fd;
    int first_read_fd;
@@ -46,7 +46,7 @@ static void FdEventThreadFunc(void*) {
    fdevent_loop();
    fdevent_loop();
}
}


constexpr auto SLEEP_FOR_FDEVENT = std::chrono::milliseconds(100);
constexpr auto SLEEP_FOR_FDEVENT = 100ms;


TEST_F(LocalSocketTest, smoke) {
TEST_F(LocalSocketTest, smoke) {
    // Join two socketpairs with a chain of intermediate socketpairs.
    // Join two socketpairs with a chain of intermediate socketpairs.
@@ -231,7 +231,7 @@ static void ClientThreadFunc() {
    std::string error;
    std::string error;
    int fd = network_loopback_client(5038, SOCK_STREAM, &error);
    int fd = network_loopback_client(5038, SOCK_STREAM, &error);
    ASSERT_GE(fd, 0) << error;
    ASSERT_GE(fd, 0) << error;
    std::this_thread::sleep_for(std::chrono::milliseconds(200));
    std::this_thread::sleep_for(200ms);
    ASSERT_EQ(0, adb_close(fd));
    ASSERT_EQ(0, adb_close(fd));
}
}


adb/sysdeps/chrono.h

0 → 100644
+46 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * 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.
 */

#pragma once

#include <chrono>

#if defined(_WIN32)
// We don't have C++14 on Windows yet.
// Reimplement std::chrono_literals ourselves until we do.

// Silence the following warning (which gets promoted to an error):
// error: literal operator suffixes not preceded by ‘_’ are reserved for future standardization
#pragma GCC system_header

constexpr std::chrono::seconds operator"" s(unsigned long long s) {
    return std::chrono::seconds(s);
}

constexpr std::chrono::duration<long double> operator"" s(long double s) {
    return std::chrono::duration<long double>(s);
}

constexpr std::chrono::milliseconds operator"" ms(unsigned long long ms) {
    return std::chrono::milliseconds(ms);
}

constexpr std::chrono::duration<long double, std::milli> operator"" ms(long double ms) {
    return std::chrono::duration<long double, std::milli>(ms);
}
#else
using namespace std::chrono_literals;
#endif
Loading