-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathFileThread.h
99 lines (86 loc) · 3.01 KB
/
FileThread.h
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
//==============================================================================
//
// FileThread.h
//
// Copyright (C) 2013-2025 Greg Utas
//
// This file is part of the Robust Services Core (RSC).
//
// RSC is free software: you can redistribute it and/or modify it under the
// terms of the Lesser GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// RSC 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 Lesser GNU General Public License
// along with RSC. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef FILETHREAD_H_INCLUDED
#define FILETHREAD_H_INCLUDED
#include "Thread.h"
#include <string>
#include "CallbackRequest.h"
#include "NbTypes.h"
#include "SysTypes.h"
//------------------------------------------------------------------------------
namespace NodeBase
{
// Thread for file output. All threads use this, as it will eventually
// support sending files to a remote location.
//
class FileThread : public Thread
{
friend class Singleton<FileThread>;
public:
// Creates a stream where output can be directed and eventually passed
// to our Spool function.
//
static ostringstreamPtr CreateStream();
// Queues STREAM for output to the file identified by NAME. If TRUNC
// is set, an existing file with NAME is overwritten; otherwise, STREAM
// is appended to it. When STREAM has been written, WRITTEN is invoked.
// FileThread assumes ownership of STREAM and WRITTEN, which are set to
// nullptr before returning.
//
static void Spool(const std::string& name, ostringstreamPtr& stream,
CallbackRequestPtr& written, bool trunc = false);
// The same as Spool (above), but without a callback.
//
static void Spool(const std::string& name, ostringstreamPtr& stream,
bool trunc = false);
// Outputs STR to the file identified by NAME. Adds a CRLF if EOL is set.
//
static void Spool(const std::string& name,
const std::string& str, bool eol = false);
// Outputs S to the console transcript file. Adds a CRLF if EOL is set.
//
static void Record(const std::string& s, bool eol = false);
// Clears the contents of the file identified by NAME.
//
static void Truncate(const std::string& name);
// Overridden for patching.
//
void Patch(sel_t selector, void* arguments) override;
private:
// Private because this is a singleton.
//
FileThread();
// Private because this is a singleton.
//
~FileThread();
// Overridden to return a name for the thread.
//
c_string AbbrName() const override;
// Overridden to delete the singleton.
//
void Destroy() override;
// Overridden to dequeue file output requests.
//
void Enter() override;
};
}
#endif