Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[linux] Add GDBus support in PlatformMgr to drive DBUS communication. #1557

Merged
merged 2 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,25 @@ if test "${CHIP_DEVICE_LAYER_TARGET_LINUX}" = 1; then
)
fi

#
#
# GIO
#

if test "${CHIP_DEVICE_LAYER_TARGET_LINUX}" = 1; then
PKG_CHECK_MODULES([GIO], [gio-2.0])

# Check for GIO library is available.
AC_CHECK_LIB([gio-2.0], [g_bus_get_sync],
[
AC_DEFINE([CHIP_WITH_GIO], [1], [Define to 1 to build CHIP with GIO])
],
[
AC_DEFINE([CHIP_WITH_GIO], [0], [Define to 0 to build CHIP without GIO])
]
)
fi

#
# Sockets
#
Expand Down Expand Up @@ -2350,6 +2369,7 @@ AC_MSG_NOTICE([
PThreads compile flags : ${PTHREAD_CFLAGS:--}
PThreads link libraries : ${PTHREAD_LIBS:--}
IniPP compile flags : ${INIPP_CPPFLAGS:--}
GIO compile flags : ${GIO_CFLAGS:--}
C Preprocessor : ${CPP}
C Compiler : ${CC}
C++ Preprocessor : ${CXXCPP}
Expand Down
28 changes: 28 additions & 0 deletions src/platform/Linux/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,36 @@
#include <platform/PlatformManager.h>
#include <platform/internal/GenericPlatformManagerImpl_POSIX.ipp>

#include <thread>

namespace chip {
namespace DeviceLayer {

PlatformManagerImpl PlatformManagerImpl::sInstance;

#if CHIP_WITH_GIO
static void GDBus_Thread()
{
GMainLoop * loop = g_main_loop_new(nullptr, false);

g_main_loop_run(loop);
g_main_loop_unref(loop);
}
#endif

CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
{
CHIP_ERROR err;

#if CHIP_WITH_GIO
GError * error = NULL;

this->mpGDBusConnection = UniqueGDBusConnection(g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error));

std::thread gdbusThread(GDBus_Thread);
gdbusThread.detach();
#endif

// Initialize the configuration system.
err = Internal::PosixConfig::Init();
SuccessOrExit(err);
Expand All @@ -49,5 +70,12 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
return err;
}

#if CHIP_WITH_GIO
GDBusConnection * PlatformManagerImpl::GetGDBusConnection()
{
return this->mpGDBusConnection.get();
}
#endif

} // namespace DeviceLayer
} // namespace chip
19 changes: 17 additions & 2 deletions src/platform/Linux/PlatformManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@
#ifndef PLATFORM_MANAGER_IMPL_H
#define PLATFORM_MANAGER_IMPL_H

#include <memory>
#include <platform/internal/GenericPlatformManagerImpl_POSIX.h>

#if CHIP_WITH_GIO
#include <gio/gio.h>
#endif

namespace chip {
namespace DeviceLayer {

Expand All @@ -44,8 +49,9 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener

public:
// ===== Platform-specific members that may be accessed directly by the application.

/* none so far */
#if CHIP_WITH_GIO
GDBusConnection * GetGDBusConnection();
#endif

private:
// ===== Methods that implement the PlatformManager abstract interface.
Expand All @@ -59,6 +65,15 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener
friend class Internal::BLEManagerImpl;

static PlatformManagerImpl sInstance;

#if CHIP_WITH_GIO
struct GDBusConnectionDeleter
{
void operator()(GDBusConnection * conn) { g_object_unref(conn); }
};
using UniqueGDBusConnection = std::unique_ptr<GDBusConnection, GDBusConnectionDeleter>;
UniqueGDBusConnection mpGDBusConnection;
#endif
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/platform/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ if CHIP_DEVICE_LAYER_TARGET_LINUX
SUBDIRS += tests

libDeviceLayer_a_CPPFLAGS += \
$(GIO_CFLAGS) \
$(INIPP_CPPFLAGS) \
$(NULL)

Expand Down
17 changes: 13 additions & 4 deletions src/platform/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,19 @@ AM_CPPFLAGS = \
$(NULL)

if CHIP_DEVICE_LAYER_TARGET_LINUX
AM_CPPFLAGS += \
$(GIO_CFLAGS) \
$(NULL)

if CHIP_WITH_OT_BR_POSIX
AM_CPPFLAGS += \
$(DBUS_CFLAGS) \
$(OT_BR_POSIX_CPPFLAGS) \
$(NULL)
libPlatformTests_a_SOURCES += TestThreadStackMgr.cpp
endif
endif
endif # CHIP_WITH_OT_BR_POSIX
endif # CHIP_DEVICE_LAYER_TARGET_LINUX


CHIP_LDADD = \
$(top_builddir)/src/platform/libDeviceLayer.a \
Expand All @@ -86,13 +91,17 @@ CHIP_LDADD = \
$(NULL)

if CHIP_DEVICE_LAYER_TARGET_LINUX
CHIP_LDADD += \
$(GIO_CFLAGS) $(GIO_LIBS) \
$(NULL)

if CHIP_WITH_OT_BR_POSIX
CHIP_LDADD += \
$(DBUS_LIBS) \
$(OT_BR_POSIX_LDFLAGS) $(OT_BR_POSIX_LIBS) \
$(NULL)
endif
endif
endif # CHIP_WITH_OT_BR_POSIX
endif # CHIP_DEVICE_LAYER_TARGET_LINUX

COMMON_LDADD = \
libPlatformTests.a \
Expand Down