1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
/*
* Copyright 2005-2021 Fabrice Colin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _DAEMONSTATE_HH
#define _DAEMONSTATE_HH
#include <sys/select.h>
#include <string>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
#include <sigc++/sigc++.h>
#ifdef HAVE_DBUS
#include <giomm/dbusconnection.h>
#include <giomm/dbusproxy.h>
#endif
#include "CrawlHistory.h"
#ifdef HAVE_DBUS
#include "DBusIndex.h"
#endif
#include "MonitorInterface.h"
#include "MonitorHandler.h"
#include "PinotSettings.h"
#include "PinotDBus_stub.h"
#include "SearchProvider_stub.h"
#include "WorkerThreads.h"
class DaemonState : public QueueManager
{
public:
DaemonState();
virtual ~DaemonState();
typedef enum { LOW_DISK_SPACE = 0, ON_BATTERY, CRAWLING, STOPPED, DISCONNECTED, SHOULD_FLUSH } StatusFlag;
virtual void disconnect(void);
void register_session(void);
void start(bool isReindex);
bool start_crawling(void);
void stop_crawling(void);
void on_thread_end(WorkerThread *pThread);
void on_message_filefound(DocumentInfo docInfo, bool isDirectory);
sigc::signal1<void, int>& getQuitSignal(void);
void set_flag(StatusFlag flag);
bool is_flag_set(StatusFlag flag);
void reset_flag(StatusFlag flag);
void flush_and_reclaim(void);
protected:
#ifdef HAVE_DBUS
class DBusIntrospectHandler : public org::freedesktop::DBus::IntrospectableStub
{
public:
DBusIntrospectHandler();
virtual ~DBusIntrospectHandler();
protected:
virtual void Introspect(IntrospectableStub::MethodInvocation &invocation);
};
class DBusMessageHandler : public com::github::fabricecolin::PinotStub
{
public:
DBusMessageHandler(DaemonState *pServer);
virtual ~DBusMessageHandler();
bool mustQuit(void) const;
protected:
DaemonState *m_pServer;
time_t m_flushTime;
bool m_mustQuit;
virtual void GetStatistics(PinotStub::MethodInvocation &invocation);
virtual void Reload(PinotStub::MethodInvocation &invocation);
virtual void Stop(PinotStub::MethodInvocation &invocation);
virtual void GetDocumentInfo(guint32 docId,
PinotStub::MethodInvocation &invocation);
virtual void GetDocumentTermsCount(guint32 docId,
PinotStub::MethodInvocation &invocation);
virtual void GetDocumentTerms(guint32 docId,
PinotStub::MethodInvocation &invocation);
virtual void GetLabels(PinotStub::MethodInvocation &invocation);
virtual void AddLabel(const Glib::ustring &label,
PinotStub::MethodInvocation &invocation);
virtual void DeleteLabel(const Glib::ustring &label,
PinotStub::MethodInvocation &invocation);
virtual void HasLabel(guint32 docId,
const Glib::ustring &label,
PinotStub::MethodInvocation &invocation);
virtual void GetDocumentLabels(guint32 docId,
PinotStub::MethodInvocation &invocation);
virtual void SetDocumentLabels(guint32 docId,
const std::vector<Glib::ustring> &labels,
bool resetLabels,
PinotStub::MethodInvocation &invocation);
virtual void SetDocumentsLabels(const std::vector<Glib::ustring> &docIds,
const std::vector<Glib::ustring> &labels,
bool resetLabels,
PinotStub::MethodInvocation &invocation);
virtual void HasDocument(const Glib::ustring &url,
PinotStub::MethodInvocation &invocation);
virtual void GetCloseTerms(const Glib::ustring &term,
PinotStub::MethodInvocation &invocation);
virtual void GetDocumentsCount(const Glib::ustring &label,
PinotStub::MethodInvocation &invocation);
virtual void ListDocuments(const Glib::ustring &term,
guint32 termType, guint32 maxCount, guint32 startOffset,
PinotStub::MethodInvocation &invocation);
virtual void UpdateDocument(guint32 docId,
PinotStub::MethodInvocation &invocation);
virtual void SetDocumentInfo(guint32 docId,
const std::vector<std::tuple<Glib::ustring,Glib::ustring>> &fields,
PinotStub::MethodInvocation &invocation);
virtual void Query(const Glib::ustring &engineType,
const Glib::ustring &engineName,
const Glib::ustring &searchText,
guint32 startDoc,
guint32 maxHits,
PinotStub::MethodInvocation &invocation);
virtual void SimpleQuery(const Glib::ustring &searchText,
guint32 maxHits,
PinotStub::MethodInvocation &invocation);
virtual bool DaemonVersion_setHandler(const Glib::ustring &value);
virtual Glib::ustring DaemonVersion_get();
virtual bool IndexFlushEpoch_setHandler(guint32 value);
virtual guint32 IndexFlushEpoch_get();
};
class DBusSearchProvider : public org::gnome::Shell::SearchProvider2Stub
{
public:
DBusSearchProvider(DaemonState *pServer);
virtual ~DBusSearchProvider();
protected:
DaemonState *m_pServer;
virtual void GetInitialResultSet(const std::vector<Glib::ustring> &terms,
MethodInvocation &invocation);
virtual void GetSubsearchResultSet(const std::vector<Glib::ustring> &previous_results,
const std::vector<Glib::ustring> &terms,
MethodInvocation &invocation);
virtual void GetResultMetas(const std::vector<Glib::ustring> &identifiers,
MethodInvocation &invocation);
virtual void ActivateResult(const Glib::ustring &identifier,
const std::vector<Glib::ustring> &terms,
guint32 timestamp,
MethodInvocation &invocation);
virtual void LaunchSearch(const std::vector<Glib::ustring> &terms,
guint32 timestamp,
MethodInvocation &invocation);
};
Glib::RefPtr<Gio::DBus::Connection> m_refSessionBus;
DBusIntrospectHandler m_introspectionHandler;
DBusMessageHandler m_messageHandler;
DBusSearchProvider m_searchProvider;
Glib::RefPtr<Gio::DBus::Proxy> m_powerProxy;
guint m_connectionId;
#endif
bool m_isReindex;
bool m_tryReload;
bool m_readyToReload;
fd_set m_flagsSet;
CrawlHistory m_crawlHistory;
MonitorInterface *m_pDiskMonitor;
MonitorHandler *m_pDiskHandler;
sigc::connection m_timeoutConnection;
sigc::signal1<void, int> m_signalQuit;
unsigned int m_crawlers;
std::queue<PinotSettings::IndexableLocation> m_crawlQueue;
#ifdef HAVE_DBUS
void handle_power_properties_changed(const Gio::DBus::Proxy::MapChangedProperties &changed_properties,
const std::vector<Glib::ustring> &invalidated_properties);
#endif
bool on_activity_timeout(void);
void check_battery_state(void);
bool crawl_location(const PinotSettings::IndexableLocation &location);
};
#endif // _DAEMONSTATE_HH
|