nux-1.14.0
|
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- 00002 /* 00003 * Copyright 2011 Inalogic® Inc. 00004 * 00005 * This program is free software: you can redistribute it and/or modify it 00006 * under the terms of the GNU Lesser General Public License, as 00007 * published by the Free Software Foundation; either version 2.1 or 3.0 00008 * of the License. 00009 * 00010 * This program is distributed in the hope that it will be useful, but 00011 * WITHOUT ANY WARRANTY; without even the implied warranties of 00012 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00013 * PURPOSE. See the applicable version of the GNU Lesser General Public 00014 * License for more details. 00015 * 00016 * You should have received a copy of both the GNU Lesser General Public 00017 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00018 * 00019 * Authored by: Tim Penhey <tim.penhey@canonical.com> 00020 * 00021 */ 00022 #ifndef NUXCORE_ASYNC_FILE_WRITER_H 00023 #define NUXCORE_ASYNC_FILE_WRITER_H 00024 00025 #include <string> 00026 #include <sigc++/sigc++.h> 00027 00028 namespace nux 00029 { 00030 00037 class AsyncFileWriter 00038 { 00039 public: 00040 AsyncFileWriter(std::string const& filename); 00041 // Destructor kills any pending async requests, and close the file 00042 // synchronously if it is open. 00043 ~AsyncFileWriter(); 00044 00045 // Queue the data for writing. It'll happen some time. 00046 void Write(std::string const& data); 00047 // Close the file asynchronously. When the file is closed, the closed 00048 // signal is emitted. 00049 void Close(); 00050 00051 bool IsClosing() const; 00052 00053 sigc::signal<void> opened; 00054 sigc::signal<void> closed; 00055 00056 private: 00057 class Impl; 00058 Impl* pimpl; 00059 }; 00060 00061 } 00062 00063 #endif