mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Initial linux commit
This commit is contained in:
@@ -233,11 +233,14 @@ cc_library(
|
||||
"//location/nearby/apps/better_together/plugins/preferences_native:__subpackages__",
|
||||
"//location/nearby/cpp/sharing:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
] + select({
|
||||
deps = [] + select({
|
||||
"@platforms//os:linux": [
|
||||
"//internal/platform/implementation/linux:linux_platform_impl",
|
||||
],
|
||||
"@platforms//os:windows": [
|
||||
"//internal/platform/implementation/windows",
|
||||
],
|
||||
# Add other platforms as needed
|
||||
"//conditions:default": [
|
||||
"//internal/platform/implementation/g3",
|
||||
],
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
cc_library(
|
||||
name = "linux_platform_impl",
|
||||
srcs = [
|
||||
"device_info.cc"
|
||||
],
|
||||
hdrs = [
|
||||
"device_info.h"
|
||||
],
|
||||
deps = [
|
||||
"@sdbus_cpp//:sdbus_cpp",
|
||||
"@sdbus_cpp//:libsystemd",
|
||||
"//internal/platform:logging",
|
||||
"//internal/platform/implementation:types",
|
||||
"@com_google_absl//absl/strings"
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
@@ -0,0 +1,60 @@
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include "internal/platform/implementation/linux/device_info.h"
|
||||
#include "internal/base/file_path.h"
|
||||
|
||||
namespace nearby
|
||||
{
|
||||
namespace linux
|
||||
{
|
||||
// TODO: Add proper implementations to grab device names and types from D-bus
|
||||
|
||||
std::optional<std::string> DeviceInfo::GetOsDeviceName() const
|
||||
{
|
||||
return "TestLinux" ;
|
||||
};
|
||||
api::DeviceInfo::DeviceType DeviceInfo::GetDeviceType() const
|
||||
{
|
||||
return api::DeviceInfo::DeviceType::kLaptop;
|
||||
};
|
||||
std::optional<FilePath> DeviceInfo::GetDownloadPath() const
|
||||
{
|
||||
char* download_path = getenv("XDG_DOWNLOAD_DIR");
|
||||
if (download_path == nullptr)
|
||||
{
|
||||
download_path = getenv("HOME");
|
||||
if (download_path != nullptr)
|
||||
{
|
||||
std::string path = std::string(download_path) + "/Downloads";
|
||||
return FilePath(path);
|
||||
}
|
||||
}
|
||||
return FilePath(std::string(download_path));
|
||||
};
|
||||
std::optional<FilePath> DeviceInfo::GetLocalAppDataPath() const
|
||||
{
|
||||
char* dir = getenv("XDG_STATE_HOME");
|
||||
if (dir == nullptr)
|
||||
{
|
||||
return FilePath("/tmp");
|
||||
}
|
||||
return FilePath(std::string(dir)).append(FilePath("com.google.nearby")) ;
|
||||
}
|
||||
std::optional<FilePath> DeviceInfo::GetCommonAppDataPath() const
|
||||
{
|
||||
return GetLocalAppDataPath();
|
||||
};
|
||||
std::optional<FilePath> DeviceInfo::GetTemporaryPath() const
|
||||
{
|
||||
return FilePath("/tmp");
|
||||
}
|
||||
std::optional<FilePath> DeviceInfo::GetLogPath() const
|
||||
{
|
||||
return FilePath("/tmp/nearby/logs");
|
||||
};
|
||||
std::optional<FilePath> DeviceInfo::GetCrashDumpPath() const
|
||||
{
|
||||
return FilePath("/tmp/nearby/crashdump");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright 2022 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
|
||||
//
|
||||
// https://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.
|
||||
|
||||
#ifndef PLATFORM_IMPL_LINUX_INFO_H_
|
||||
#define PLATFORM_IMPL_LINUX_INFO_H_
|
||||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <systemd/sd-bus.h>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace linux {
|
||||
|
||||
class DeviceInfo: public api::DeviceInfo {
|
||||
public:
|
||||
~DeviceInfo() = default;
|
||||
|
||||
// Gets device name.
|
||||
std::optional<std::string> GetOsDeviceName() const override;
|
||||
api::DeviceInfo::DeviceType GetDeviceType() const override;
|
||||
api::DeviceInfo::OsType GetOsType() const override
|
||||
{
|
||||
return api::DeviceInfo::OsType::kWindows; //TODO: should probably change to linux
|
||||
};
|
||||
|
||||
// Gets known paths of current user.
|
||||
std::optional<FilePath> GetDownloadPath() const override;
|
||||
std::optional<FilePath> GetLocalAppDataPath() const override;
|
||||
std::optional<FilePath> GetCommonAppDataPath() const override;
|
||||
std::optional<FilePath> GetTemporaryPath() const override;
|
||||
std::optional<FilePath> GetLogPath() const override;
|
||||
std::optional<FilePath> GetCrashDumpPath() const override;
|
||||
|
||||
// Monitor screen status
|
||||
bool IsScreenLocked() const override
|
||||
{
|
||||
return false;
|
||||
};
|
||||
void RegisterScreenLockedListener(
|
||||
absl::string_view listener_name,
|
||||
std::function<void(api::DeviceInfo::ScreenStatus)> callback) override {return;};
|
||||
void UnregisterScreenLockedListener(
|
||||
absl::string_view listener_name) override { return;};
|
||||
|
||||
// Control device sleep
|
||||
bool PreventSleep() override {return true;};
|
||||
bool AllowSleep() override { return true;};
|
||||
};
|
||||
|
||||
} // namespace linux
|
||||
} // namespace nearby
|
||||
|
||||
#endif // PLATFORM_IMPL_LINUX_INFO_H_
|
||||
@@ -0,0 +1,95 @@
|
||||
|
||||
/*
|
||||
* This file was automatically generated by sdbus-c++-xml2cpp; DO NOT EDIT!
|
||||
*/
|
||||
|
||||
#ifndef __sdbuscpp___home_lasan_Dev_nearby_latest_internal_platform_implementation_linux_generated_avahi_proxy_h__proxy__H__
|
||||
#define __sdbuscpp___home_lasan_Dev_nearby_latest_internal_platform_implementation_linux_generated_avahi_proxy_h__proxy__H__
|
||||
|
||||
#include <sdbus-c++/sdbus-c++.h>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
namespace org {
|
||||
namespace freedesktop {
|
||||
namespace Avahi {
|
||||
|
||||
class Server_proxy
|
||||
{
|
||||
public:
|
||||
static constexpr const char* INTERFACE_NAME = "org.freedesktop.Avahi.Server";
|
||||
|
||||
protected:
|
||||
Server_proxy(sdbus::IProxy& proxy)
|
||||
: proxy_(&proxy)
|
||||
{
|
||||
}
|
||||
|
||||
Server_proxy(const Server_proxy&) = delete;
|
||||
Server_proxy& operator=(const Server_proxy&) = delete;
|
||||
Server_proxy(Server_proxy&&) = default;
|
||||
Server_proxy& operator=(Server_proxy&&) = default;
|
||||
|
||||
~Server_proxy() = default;
|
||||
|
||||
public:
|
||||
sdbus::ObjectPath ServiceBrowserNew(const int32_t& interface, const int32_t& protocol, const std::string& type, const std::string& domain)
|
||||
{
|
||||
sdbus::ObjectPath result;
|
||||
proxy_->callMethod("ServiceBrowserNew").onInterface(INTERFACE_NAME).withArguments(interface, protocol, type, domain).storeResultsTo(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::tuple<int32_t, int32_t, std::string, std::string, std::string, std::string, int32_t, std::string, uint16_t, std::vector<std::vector<uint8_t>>> ResolveService(const int32_t& interface, const int32_t& protocol, const std::string& name, const std::string& type, const std::string& domain, const int32_t& aprotocol)
|
||||
{
|
||||
std::tuple<int32_t, int32_t, std::string, std::string, std::string, std::string, int32_t, std::string, uint16_t, std::vector<std::vector<uint8_t>>> result;
|
||||
proxy_->callMethod("ResolveService").onInterface(INTERFACE_NAME).withArguments(interface, protocol, name, type, domain, aprotocol).storeResultsTo(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
sdbus::IProxy* proxy_;
|
||||
};
|
||||
|
||||
}}} // namespaces
|
||||
|
||||
namespace org {
|
||||
namespace freedesktop {
|
||||
namespace Avahi {
|
||||
|
||||
class ServiceBrowser_proxy
|
||||
{
|
||||
public:
|
||||
static constexpr const char* INTERFACE_NAME = "org.freedesktop.Avahi.ServiceBrowser";
|
||||
|
||||
protected:
|
||||
ServiceBrowser_proxy(sdbus::IProxy& proxy)
|
||||
: proxy_(&proxy)
|
||||
{
|
||||
proxy_->uponSignal("ItemNew").onInterface(INTERFACE_NAME).call([this](const int32_t& interface, const int32_t& protocol, const std::string& name, const std::string& type, const std::string& domain){ this->onItemNew(interface, protocol, name, type, domain); });
|
||||
proxy_->uponSignal("ItemRemove").onInterface(INTERFACE_NAME).call([this](const int32_t& interface, const int32_t& protocol, const std::string& name, const std::string& type, const std::string& domain){ this->onItemRemove(interface, protocol, name, type, domain); });
|
||||
}
|
||||
|
||||
ServiceBrowser_proxy(const ServiceBrowser_proxy&) = delete;
|
||||
ServiceBrowser_proxy& operator=(const ServiceBrowser_proxy&) = delete;
|
||||
ServiceBrowser_proxy(ServiceBrowser_proxy&&) = default;
|
||||
ServiceBrowser_proxy& operator=(ServiceBrowser_proxy&&) = default;
|
||||
|
||||
~ServiceBrowser_proxy() = default;
|
||||
|
||||
virtual void onItemNew(const int32_t& interface, const int32_t& protocol, const std::string& name, const std::string& type, const std::string& domain) = 0;
|
||||
virtual void onItemRemove(const int32_t& interface, const int32_t& protocol, const std::string& name, const std::string& type, const std::string& domain) = 0;
|
||||
|
||||
public:
|
||||
void Free()
|
||||
{
|
||||
proxy_->callMethod("Free").onInterface(INTERFACE_NAME);
|
||||
}
|
||||
|
||||
private:
|
||||
sdbus::IProxy* proxy_;
|
||||
};
|
||||
|
||||
}}} // namespaces
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,56 @@
|
||||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node name="/">
|
||||
<!-- org.freedesktop.Avahi.Server lives at object path "/" -->
|
||||
<interface name="org.freedesktop.Avahi.Server">
|
||||
<!-- Create a ServiceBrowser object; returns its object path -->
|
||||
<method name="ServiceBrowserNew">
|
||||
<arg name="interface" type="i" direction="in"/>
|
||||
<arg name="protocol" type="i" direction="in"/>
|
||||
<arg name="type" type="s" direction="in"/>
|
||||
<arg name="domain" type="s" direction="in"/>
|
||||
<arg name="path" type="o" direction="out"/>
|
||||
</method>
|
||||
|
||||
<!-- Resolve a found service to host/address/port/TXT -->
|
||||
<method name="ResolveService">
|
||||
<arg name="interface" type="i" direction="in"/>
|
||||
<arg name="protocol" type="i" direction="in"/>
|
||||
<arg name="name" type="s" direction="in"/>
|
||||
<arg name="type" type="s" direction="in"/>
|
||||
<arg name="domain" type="s" direction="in"/>
|
||||
<arg name="aprotocol" type="i" direction="in"/>
|
||||
|
||||
<arg name="r_interface" type="i" direction="out"/>
|
||||
<arg name="r_protocol" type="i" direction="out"/>
|
||||
<arg name="r_name" type="s" direction="out"/>
|
||||
<arg name="r_type" type="s" direction="out"/>
|
||||
<arg name="r_domain" type="s" direction="out"/>
|
||||
<arg name="r_host" type="s" direction="out"/>
|
||||
<arg name="r_aprotocol" type="i" direction="out"/>
|
||||
<arg name="r_address" type="s" direction="out"/>
|
||||
<arg name="r_port" type="q" direction="out"/>
|
||||
<!-- TXT records = array of byte arrays (aay) -->
|
||||
<arg name="r_txt" type="aay" direction="out"/>
|
||||
</method>
|
||||
</interface>
|
||||
|
||||
<!-- The ServiceBrowser object we get back from ServiceBrowserNew -->
|
||||
<interface name="org.freedesktop.Avahi.ServiceBrowser">
|
||||
<method name="Free"/>
|
||||
<signal name="ItemNew">
|
||||
<arg name="interface" type="i"/>
|
||||
<arg name="protocol" type="i"/>
|
||||
<arg name="name" type="s"/>
|
||||
<arg name="type" type="s"/>
|
||||
<arg name="domain" type="s"/>
|
||||
</signal>
|
||||
<signal name="ItemRemove">
|
||||
<arg name="interface" type="i"/>
|
||||
<arg name="protocol" type="i"/>
|
||||
<arg name="name" type="s"/>
|
||||
<arg name="type" type="s"/>
|
||||
<arg name="domain" type="s"/>
|
||||
</signal>
|
||||
</interface>
|
||||
</node>
|
||||
Reference in New Issue
Block a user