mirror of
https://github.com/google/cdc-file-transfer.git
synced 2026-09-13 01:10:44 +03:00
ee4118c6bf
Improves ServerArch so that it can detect the remote architecture by running uname and checking %PROCESSOR_ARCHITECTURE%. So far, only x64 Linux and x64 Windows are supported, but in the future it is easy to add support for others, e.g. aarch64, as well. Before the detection is run, the remote architecture is guessed first based on the destination. For instance, if the destination directory starts with "C:\", it pretty much means Windows. If cdc_rsync_server exists and runs fine, there's no need for detection. Since also PortManager depends on the remote architecture, it has to be adjusted as well. So far, PortManager assumeed that "local" means Windows and "remote" means Linux. This is no longer the case for syncing to Windows devices, so this CL adds the necessary abstractions to PortManager. Also refactors ArchType into a separate class in common, since it is used now from several places. It is also expanded to handle future changes that add support for different processor architectures, e.g. aarch64.
71 lines
1.7 KiB
C++
71 lines
1.7 KiB
C++
// Copyright 2023 Google LLC
|
|
//
|
|
// 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.
|
|
|
|
#include "common/arch_type.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include "common/platform.h"
|
|
|
|
namespace cdc_ft {
|
|
|
|
static constexpr char kUnhandledArchType[] = "Unhandled arch type";
|
|
|
|
ArchType GetLocalArchType() {
|
|
// TODO(ljusten): Take CPU architecture into account.
|
|
#if PLATFORM_WINDOWS
|
|
return ArchType::kWindows_x86_64;
|
|
#elif PLATFORM_LINUX
|
|
return ArchType::kLinux_x86_64;
|
|
#endif
|
|
}
|
|
|
|
bool IsWindowsArchType(ArchType arch_type) {
|
|
switch (arch_type) {
|
|
case ArchType::kWindows_x86_64:
|
|
return true;
|
|
case ArchType::kLinux_x86_64:
|
|
return false;
|
|
default:
|
|
assert(!kUnhandledArchType);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool IsLinuxArchType(ArchType arch_type) {
|
|
switch (arch_type) {
|
|
case ArchType::kWindows_x86_64:
|
|
return false;
|
|
case ArchType::kLinux_x86_64:
|
|
return true;
|
|
default:
|
|
assert(!kUnhandledArchType);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
const char* GetArchTypeStr(ArchType arch_type) {
|
|
switch (arch_type) {
|
|
case ArchType::kWindows_x86_64:
|
|
return "Windows_x86_64";
|
|
case ArchType::kLinux_x86_64:
|
|
return "Linux_x86_64";
|
|
default:
|
|
assert(!kUnhandledArchType);
|
|
return "Unknown";
|
|
}
|
|
}
|
|
|
|
} // namespace cdc_ft
|