Skip to content

Commit

Permalink
refactor: move daemon to deepin-service-manager
Browse files Browse the repository at this point in the history
1.rename dbus service
2.run grandsearchdaemon in deepin-service-manager

Log: refactor daemon
Task: https://pms.uniontech.com/story-view-36057.html
  • Loading branch information
Lighto-Ku authored and deepin-bot[bot] committed Sep 20, 2024
1 parent 092c4f7 commit 09b2938
Show file tree
Hide file tree
Showing 115 changed files with 103 additions and 343 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ src/environments.h
CMakeLists.txt.user

build-ut/
build/

*.qm

Expand Down
4 changes: 2 additions & 2 deletions 3rdparty/interfaces/daemongrandsearchinterface.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* This file was generated by qdbusxml2cpp version 0.8
* Command line was: qdbusxml2cpp com.deepin.dde.daemon.GrandSearch.xml -c DaemonGrandSearchInterface -p daemongrandsearchinterface
* Command line was: qdbusxml2cpp org.deepin.dde.GrandSearchDaemon.xml -c DaemonGrandSearchInterface -p daemongrandsearchinterface
*
* qdbusxml2cpp is Copyright (C) 2017 The Qt Company Ltd.
* qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd.
*
* This is an auto-generated file.
* This file may have been hand-edited. Look for HAND-EDIT comments
Expand Down
18 changes: 8 additions & 10 deletions 3rdparty/interfaces/daemongrandsearchinterface.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* This file was generated by qdbusxml2cpp version 0.8
* Command line was: qdbusxml2cpp com.deepin.dde.daemon.GrandSearch.xml -c DaemonGrandSearchInterface -p daemongrandsearchinterface
* Command line was: qdbusxml2cpp org.deepin.dde.GrandSearchDaemon.xml -c DaemonGrandSearchInterface -p daemongrandsearchinterface
*
* qdbusxml2cpp is Copyright (C) 2017 The Qt Company Ltd.
* qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd.
*
* This is an auto-generated file.
* Do not edit! All changes made to it will be lost.
Expand All @@ -23,18 +23,18 @@
namespace GrandSearch {

/*
* Proxy class for interface com.deepin.dde.daemon.GrandSearch
* Proxy class for interface org.deepin.dde.GrandSearchDaemon
*/
class DaemonGrandSearchInterface: public QDBusAbstractInterface
{
Q_OBJECT
public:
static inline const char *staticInterfaceName()
{ return "com.deepin.dde.daemon.GrandSearch"; }
{ return "org.deepin.dde.GrandSearchDaemon"; }
static inline const char *staticServiceName()
{ return "com.deepin.dde.daemon.GrandSearch"; }
{ return "org.deepin.dde.GrandSearchDaemon"; }
static inline const char *staticObjectPath()
{ return "/com/deepin/dde/daemon/GrandSearch"; }
{ return "/org/deepin/dde/GrandSearchDaemon"; }

public:
explicit DaemonGrandSearchInterface(QObject *parent = nullptr);
Expand Down Expand Up @@ -114,12 +114,10 @@ public Q_SLOTS: // METHODS
void SearchCompleted(const QString &session);
};

namespace com {
namespace org {
namespace deepin {
namespace dde {
namespace daemon {
typedef DaemonGrandSearchInterface GrandSearch;
}
typedef DaemonGrandSearchInterface GrandSearchDaemon;
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ endif()
#Indentify the version
find_package(DtkCMake REQUIRED)

if (1 OR ${DEEPIN_OS_VERSION} MATCHES "23")
if (1 OR ${DEEPIN_OS_VERSION} MATCHES "^(23|25)$")
add_definitions(-DCOMPILE_ON_V23)
set(COMPLIE_ON_V23 TRUE)
message("COMPILE ON v23")
message("COMPILE ON v2x")
else()
add_definitions(-DCOMPILE_ON_V20)
set(COMPLIE_ON_V20 TRUE)
Expand Down Expand Up @@ -90,8 +90,7 @@ set(PLUGIN_SEARCHER_DIR "${DAEMON_PLUGIN_DIR}/searcher")
add_definitions(-DPLUGIN_SEARCHER_DIR="${PLUGIN_SEARCHER_DIR}")

add_subdirectory(src/grand-search)
add_subdirectory(src/libgrand-search-daemon)
add_subdirectory(src/grand-search-daemon)
add_subdirectory(src/dde-grand-search-daemon)
add_subdirectory(src/grand-search-dock-plugin)
add_subdirectory(src/preview-plugin)
add_subdirectory(src/tools/semanticparser)
Expand Down
3 changes: 2 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Build-Depends: debhelper (>= 9),
libdeepin-pdfium-dev,
libjpeg62-turbo-dev,
liblucene++-dev,
libboost-dev
libboost-dev,
libdeepin-service-framework-dev
Standards-Version: 3.9.8
Homepage: http://www.deepin.org/

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -pie")

# 设置库名
set(LIB_NAME ${DAEMON_LIB_NAME})
# 设置名称
set(BIN_NAME ${DAEMON_BIN_NAME})

# 依赖包
find_package(PkgConfig REQUIRED)
Expand All @@ -21,6 +21,9 @@ find_package(Qt5 COMPONENTS
Concurrent
DBus
REQUIRED)
find_package(deepin-qdbus-service REQUIRED)

add_definitions(-DSERVICE_CONFIG_DIR="${CMAKE_INSTALL_PREFIX}/share/deepin-service-manager/")

set(Qt_LIBS
Qt5::Core
Expand All @@ -35,6 +38,7 @@ set(LINK_LIBS
${Qt_LIBS}
${DtkCore_LIBRARIES}
${DtkWidget_LIBRARIES}
${deepin-qdbus-service_LIBRARIES}
)

# 源文件
Expand Down Expand Up @@ -190,6 +194,7 @@ set(UTILS

set(SRCS
main.cpp

${GLOBAL_SRC}
${UTILS}
${DBUS}
Expand All @@ -202,29 +207,27 @@ set(SRCS
# 资源文件
qt5_add_resources(QRC_FILES utils/dict.qrc)

#
add_library(${LIB_NAME}
SHARED
# 执行程序
add_executable(${BIN_NAME}
${SRCS} ${QRC_FILES}
)

# 默认会生成liblib开头的库,这里重命名生成lib开头
set_target_properties(${LIB_NAME} PROPERTIES OUTPUT_NAME ${DAEMON_BIN_NAME})
)

target_include_directories(${LIB_NAME} PUBLIC
target_include_directories(${BIN_NAME} PUBLIC
${CMAKE_SOURCE_DIR}/include
${DtkWidget_INCLUDE_DIRS}
${PROJECT_3RDPARTY_PATH}/fsearch
${GLIB_INCLUDE_DIRS}
${PCRE_INCLUDE_DIRS}
${deepin-qdbus-service_INCLUDE_DIR}
)

target_link_libraries(${LIB_NAME} PRIVATE
target_link_libraries(${BIN_NAME} PRIVATE
${LINK_LIBS}
)

# lib
install(TARGETS ${LIB_NAME} LIBRARY DESTINATION ${DAEMON_LIB_BASE_DIR})
install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES grand-search-daemon.json DESTINATION share/deepin-service-manager/other/)
install(FILES org.deepin.dde.GrandSearchDaemon.service DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/dbus-1/services)

# 扩展搜索插件目录
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/.readme DESTINATION ${PLUGIN_SEARCHER_DIR})
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ void GrandSearchInterfacePrivate::onSearchCompleted()
}

GrandSearchInterface::GrandSearchInterface(QObject *parent)
: QObject(parent)
: QDBusService(parent)
, d(new GrandSearchInterfacePrivate(this))
{

initPolicy(QDBusConnection::SessionBus, QString(SERVICE_CONFIG_DIR) + "other/grand-search-daemon.json");
}

GrandSearchInterface::~GrandSearchInterface()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
#ifndef GRANDSEARCHINTERFACE_H
#define GRANDSEARCHINTERFACE_H

#include <qdbusservice.h>

#include <QObject>
#include <QDBusContext>
#include <QMap>

//后端程序DBus服务
#define GrandSearchServiceName "com.deepin.dde.daemon.GrandSearch"
#define GrandSearchServicePath "/com/deepin/dde/daemon/GrandSearch"
#define GrandSearchServiceInterface "com.deepin.dde.daemon.GrandSearch"
#define GrandSearchServiceName "org.deepin.dde.GrandSearchDaemon"
#define GrandSearchServicePath "/org/deepin/dde/GrandSearchDaemon"
#define GrandSearchServiceInterface "org.deepin.dde.GrandSearchDaemon"

namespace GrandSearch {

class GrandSearchInterfacePrivate;
class GrandSearchInterface : public QObject, public QDBusContext
class GrandSearchInterface : public QDBusService, public QDBusContext
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", GrandSearchServiceInterface)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="com.deepin.dde.daemon.GrandSearch">
<interface name="org.deepin.dde.GrandSearchDaemon">
<signal name="Matched">
<arg name="session" type="s" direction="out"/>
</signal>
Expand Down
10 changes: 10 additions & 0 deletions src/dde-grand-search-daemon/grand-search-daemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "org.deepin.dde.GrandSearchDaemon",
"policyStartType": "OnDemand",
"idleTime": 10,
"policy": [
{
"path": "/org/deepin/dde/GrandSearchDaemon"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
#include <QDBusError>
#include <QDebug>
#include <QThread>
#include <QDir>

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

GRANDSEARCH_USE_NAMESPACE
DCORE_USE_NAMESPACE
DWIDGET_USE_NAMESPACE
DGUI_USE_NAMESPACE

static GrandSearchInterface *instance = nullptr;

Expand Down Expand Up @@ -51,7 +56,7 @@ int startGrandSearchDaemon(int argc, char *argv[])

//注册DBus服务
{
QDBusConnection session = QDBusConnection::sessionBus();
QDBusConnection session = interface->qDbusConnection();
if (!session.registerService(GrandSearchServiceName)) {
qCritical() << "registerService Failed, maybe service exist" << GrandSearchServiceName << QDBusError::errorString(session.lastError().type());
delete interface;
Expand Down Expand Up @@ -106,6 +111,49 @@ int grandSearchDaemonLibVersion()
return QT_VERSION_CHECK(DGSLIB_VERSION_MAJOR, DGSLIB_VERSION_MINOR, DGSLIB_VERSION_PATCH);
}

static void appExitHandler(int sig) {
qInfo() << "signal" << sig << "exit.";

//释放资源,退出插件子进程。
qApp->quit();
}

int main(int argc, char *argv[])
{
//安全退出
signal(SIGINT, appExitHandler);
signal(SIGQUIT, appExitHandler);
signal(SIGTERM, appExitHandler);

DApplication app(argc, argv);

{
QString dateTime = QDateTime::currentDateTime().toString(Qt::ISODateWithMs);
//设置应用信息
app.setOrganizationName("deepin");
app.setApplicationName("dde-grand-search-daemon");
app.setApplicationVersion(VERSION);

// 设置终端和文件记录日志
const QString logFormat = "%{time}{yyyyMMdd.HH:mm:ss.zzz}[%{type:1}][%{function:-35} %{line:-4} %{threadid} ] %{message}\n";
DLogManager::setLogFormat(logFormat);
DLogManager::registerConsoleAppender();
DLogManager::registerFileAppender();
qInfo() << dateTime << "starting " << app.applicationName() << app.applicationVersion() << getpid();
}

//初始化
int ret = startGrandSearchDaemon(argc, argv);
if (ret != 0) {
qCritical() << "initialization failed.";
return ret;
}
ret = app.exec();
stopGrandSearchDaemon();

return ret;
}

#ifdef __cplusplus
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[D-BUS Service]
Name=org.deepin.dde.GrandSearchDaemon
Exec=/usr/bin/dde-grand-search-daemon
File renamed without changes.
76 changes: 0 additions & 76 deletions src/grand-search-daemon/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 09b2938

Please sign in to comment.