blob: 4e5e3017d4aa7ae3fc93b98edaefe67bdcc877a5 [file] [log] [blame]
// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef LORGNETTE_DAEMON_H_
#define LORGNETTE_DAEMON_H_
#include <string>
#include <base/cancelable_callback.h>
#include <base/memory/scoped_ptr.h>
#include <base/message_loop.h>
#include <dbus-c++/glib-integration.h>
#include <dbus-c++/util.h>
namespace base {
class MessageLoopProxy;
} // namespace base
namespace lorgnette {
class Manager;
class Daemon {
public:
// DBus interface to occupy.
static const char kInterfaceName[];
// User and group to run the lorgnette process.
static const char kScanGroupName[];
static const char kScanUserName[];
Daemon();
~Daemon();
// Setup DBus resources for main loop.
void Start();
// Run main loop for scan manager.
void Run();
// Starts the termination actions in the manager.
void Quit();
private:
friend class DaemonTest;
// Daemon will automatically shutdown after this length of idle time.
static const int kShutdownTimeoutMilliseconds;
// Restarts a timer for the termination of the daemon process.
void PostponeShutdown();
scoped_ptr<MessageLoop> dont_use_directly_;
scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
scoped_ptr<DBus::Glib::BusDispatcher> dispatcher_;
scoped_ptr<DBus::Connection> connection_;
scoped_ptr<Manager> manager_;
base::CancelableClosure shutdown_callback_;
DISALLOW_COPY_AND_ASSIGN(Daemon);
};
} // namespace lorgnette
#endif // LORGNETTE_DAEMON_H_