blob: 5743a842ac5f7377a1f25549054cc23005af78e1 [file] [log] [blame]
// Copyright (c) 2012 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.
#include <glib.h>
#include <sys/types.h>
#include <base/callback.h>
#include "cros-disks/process.h"
namespace cros_disks {
// An implementation of Process that uses Glib to execute a process.
class GlibProcess : public Process {
// Callback upon the completion or termination of a process.
typedef base::Callback<void(GlibProcess* process)> Callback;
virtual ~GlibProcess();
// Implements Process::Start() to start a process without waiting
// for it to terminate. Return true on success.
virtual bool Start();
int status() const { return status_; }
void set_callback(const Callback& callback) { callback_ = callback; }
// Called by OnChildWatchNotify() to set the process termination status
// and perform proper cleanup.
void OnTerminated(int status);
// Called by g_child_watch_add() upon process termination.
static void OnChildWatchNotify(GPid pid, gint status, gpointer data);
// Termination status of the process (default to 0 if the process has not
// started). See wait(2) for details.
int status_;
// Glib specific event source ID returned by g_child_watch_add().
guint child_watch_id_;
// Callback to invoke when the process terminates.
Callback callback_;
} // namespace cros_disks