File: SC_LanguageClient.h

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 80,296 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (162 lines) | stat: -rw-r--r-- 5,401 bytes parent folder | download | duplicates (4)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*  -*- c++ -*-
    Abstract interpreter interface.
    Copyright (c) 2003 2004 stefan kersten.
    Copyright (c) 2013 tim blechmann.

    ====================================================================

    SuperCollider real time audio synthesis system
    Copyright (c) 2002 James McCartney. All rights reserved.
    http://www.audiosynth.com

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program 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 GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
*/

#pragma once

#include "SC_Export.h"
#include <cstdio>
#include <cstdarg>

// =====================================================================
// SC_LanguageClient - abstract sclang client.
// =====================================================================

SCLANG_DLLEXPORT class SC_LanguageClient* createLanguageClient(const char* name);
SCLANG_DLLEXPORT void destroyLanguageClient(class SC_LanguageClient*);

class SCLANG_DLLEXPORT SC_LanguageClient {
public:
    struct Options {
        Options(): mMemSpace(2 * 1024 * 1024), mMemGrow(256 * 1024), mPort(57120), mRuntimeDir(0) {}

        int mMemSpace; // memory space in bytes
        int mMemGrow; // memory growth in bytes
        int mPort; // network port number
        char* mRuntimeDir; // runtime directory
    };

protected:
    // create singleton instance
    SC_LanguageClient(const char* name);
    virtual ~SC_LanguageClient();
    friend void destroyLanguageClient(class SC_LanguageClient*);

public:
    // singleton instance access locking
    static void lockInstance();
    static void unlockInstance();

    // return the singleton instance
    static SC_LanguageClient* instance();
    static SC_LanguageClient* lockedInstance() {
        lockInstance();
        return instance();
    }

    // initialize language runtime
    void initRuntime(const Options& opt = Options());
    void shutdownRuntime();

    // return application name
    const char* getName() const;

    // library startup/shutdown
    bool isLibraryCompiled();
    void compileLibrary(bool standalone);
    void shutdownLibrary();
    void recompileLibrary(bool standalone);

    // interpreter access
    void lock();
    bool trylock();
    void unlock();

    struct VMGlobals* getVMGlobals();

    void setCmdLine(const char* buf, size_t size);
    void setCmdLine(const char* str);
    void setCmdLinef(const char* fmt, ...);
    void runLibrary(const char* methodName);
    void interpretCmdLine();
    void interpretPrintCmdLine();
    void executeFile(const char* fileName);
    void runMain();
    void stopMain();

    // post file access
    FILE* getPostFile();
    void setPostFile(FILE* file);

    // run (in case of a terminal client)
    virtual int run(int argc, char** argv);

    // post buffer output (subclass responsibility)
    //     should be thread-save.
    virtual void postText(const char* str, size_t len) = 0;
    virtual void postFlush(const char* str, size_t len) = 0;
    virtual void postError(const char* str, size_t len) = 0;
    // flush post buffer contents to screen.
    //     only called from the main language thread.
    virtual void flush() = 0;

    // command line argument handling utilities
    static void snprintMemArg(char* dst, size_t size, int arg);
    static bool parseMemArg(const char* arg, int* res);
    static bool parsePortArg(const char* arg, int* res);

    // AppClock driver
    //    to be called from client mainloop.
    void tick();
    // AppClock driver. WARNING: Must be called locked!
    // Returns whether there is anything scheduled,
    // and writes the scheduled absolute time, if any, into nextTime.
    bool tickLocked(double* nextTime);

protected:
    // language notifications, subclasses can override

    // called after language runtime has been initialized
    virtual void onInitRuntime();
    // called after the library has been compiled
    virtual void onLibraryStartup();
    // called before the library is shut down
    virtual void onLibraryShutdown();
    // called after the interpreter has been started
    virtual void onInterpStartup();

    void runLibrary(struct PyrSymbol* pyrSymbol);

private:
    friend void closeAllGUIScreens();
    friend void initGUIPrimitives();
    friend void initGUI();

private:
    class HiddenLanguageClient* mHiddenClient;
};

// =====================================================================
// library functions
// =====================================================================

extern void setPostFile(FILE* file);
extern "C" int vpost(const char* fmt, va_list vargs);
extern void post(const char* fmt, ...);
extern void postfl(const char* fmt, ...);
extern void postText(const char* text, long length);
extern void postChar(char c);
extern void error(const char* fmt, ...);
extern void flushPostBuf();