yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
2.8 KiB89 linesraw
1// slang-process.h
2#ifndef SLANG_PROCESS_H
3#define SLANG_PROCESS_H
4
5#include "slang-command-line.h"
6#include "slang-io.h"
7#include "slang-list.h"
8#include "slang-stream.h"
9#include "slang-string-escape-util.h"
10#include "slang-string.h"
11
12namespace Slang
13{
14
15class Process : public RefObject
16{
17public:
18    typedef uint32_t Flags;
19    struct Flag
20    {
21        enum Enum : Flags
22        {
23            // Ignored on non-Windows platforms
24            AttachDebugger = 0x01,
25            DisableStdErrRedirection = 0x02
26        };
27    };
28
29    /// Get the stream for the type
30    Stream* getStream(StdStreamType type) const { return m_streams[Index(type)]; }
31
32    /// Get the value returned from the process when it exited/returned.
33    int32_t getReturnValue() const { return m_returnValue; }
34
35    /// True if the process has terminated
36    virtual bool isTerminated() = 0;
37
38    /// Blocks until the process has terminated or the timeout completes
39    /// Can optionally supply a timeout time. -1 means 'infinite' and is the default.
40    /// Note that the timeOut is only used approximately.
41    /// Returns true if has terminated.
42    virtual bool waitForTermination(Int timeOutInMs = -1) = 0;
43
44    /// Terminate the process gracefully.
45    /// After calling it may take time before the process actually terminates
46    /// Ie calling isTerminated directly after `terminate` may return false.
47    /// The return code depending on implementation/termination style, may not be set.
48    virtual void terminate(int32_t returnCode) = 0;
49
50    /// Kill the process - attempt to terminate immediately.
51    virtual void kill(int32_t returnCode) = 0;
52
53    /// The quoting style used for the command line on this target. Currently just uses Space,
54    /// but in future may take into account platform sec
55    static StringEscapeHandler* getEscapeHandler();
56
57    /// Get the suffix used on this platform
58    static UnownedStringSlice getExecutableSuffix();
59
60    /// Create a process using the executable/args defined from the commandLine
61    static SlangResult create(
62        const CommandLine& commandLine,
63        Process::Flags flags,
64        RefPtr<Process>& outProcess);
65
66    /// Sleep the current thread for time specified in milliseconds. 0 indicates to OS ok to yield
67    /// this thread.
68    static void sleepCurrentThread(Int timeInMs);
69
70    /// Get a standard stream
71    static SlangResult getStdStream(StdStreamType type, RefPtr<Stream>& out);
72
73    /// Get the clock frequency
74    static uint64_t getClockFrequency();
75
76    /// Get the clock tick.
77    static uint64_t getClockTick();
78
79    static uint32_t getId();
80
81protected:
82    int32_t m_returnValue = 0; ///< Value returned if process terminated
83    RefPtr<Stream>
84        m_streams[Index(StdStreamType::CountOf)]; ///< Streams to communicate with the process
85};
86
87} // namespace Slang
88
89#endif // SLANG_PROCESS_H