Real Time Open Sound Control librtosc
savefile.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Johannes Lorenz
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
32#ifndef RTOSC_SAVEFILE
33#define RTOSC_SAVEFILE
34
35#include <string>
36#include <rtosc/rtosc.h>
37#include <rtosc/rtosc-version.h>
38
39namespace rtosc {
40
54std::string get_changed_values(const struct Ports& ports, void* runtime);
55
60{
61 const struct Ports* ports;
62 void* runtime;
63 char loc[1024];
64
65protected:
66 enum proceed {
67 abort = -2,
68 discard = -1
69 };
70
72 no_dependencies,
75 };
76
81
83 bool operator()(const char* msg) { return do_dispatch(msg); }
84
85 static int default_response(size_t nargs, bool first_round,
86 dependency_t dependency);
87
88private:
91 virtual int on_dispatch(size_t portname_max, char* portname,
92 size_t maxargs, size_t nargs,
93 rtosc_arg_val_t* args,
94 bool round2, dependency_t dependency);
96 virtual bool do_dispatch(const char* msg);
97
98 friend int dispatch_printed_messages(const char* messages,
99 const struct Ports& ports,
100 void* runtime,
101 savefile_dispatcher_t *dispatcher);
102
103 friend int load_from_file(const char* file_content,
104 const struct Ports& ports, void* runtime,
105 const char* appname,
106 rtosc_version appver,
107 savefile_dispatcher_t* dispatcher);
108};
109
122int dispatch_printed_messages(const char* messages,
123 const struct Ports& ports, void* runtime,
124 savefile_dispatcher_t *dispatcher = NULL);
125
136std::string save_to_file(const struct Ports& ports, void* runtime,
137 const char* appname, rtosc_version appver,
138 std::string file_str = "");
139
152int load_from_file(const char* file_content,
153 const struct Ports& ports, void* runtime,
154 const char* appname,
155 rtosc_version appver,
156 savefile_dispatcher_t* dispatcher = NULL);
157
158}
159
160#endif // RTOSC_SAVEFILE
Class to modify and dispatch messages loaded from savefiles.
Definition: savefile.h:60
proceed
Definition: savefile.h:66
@ abort
the message shall lead to abort the savefile loading
Definition: savefile.h:67
@ discard
the message shall not be dispatched
Definition: savefile.h:68
rtosc_version app_filever
app version savefile was written with
Definition: savefile.h:79
rtosc_version app_curver
current app version
Definition: savefile.h:80
rtosc_version rtosc_filever
rtosc versinon savefile was written with
Definition: savefile.h:77
friend int load_from_file(const char *file_content, const struct Ports &ports, void *runtime, const char *appname, rtosc_version appver, savefile_dispatcher_t *dispatcher)
Read save file and dispatch contained parameters.
dependency_t
Definition: savefile.h:71
@ not_specified
default values do depend on others
Definition: savefile.h:74
@ has_dependencies
default values don't depend on others
Definition: savefile.h:73
bool operator()(const char *msg)
call this to dispatch a message
Definition: savefile.h:83
rtosc_version rtosc_curver
rtosc version of this library
Definition: savefile.h:78
friend int dispatch_printed_messages(const char *messages, const struct Ports &ports, void *runtime, savefile_dispatcher_t *dispatcher)
Scan OSC messages from human readable format and dispatch them.
Definition of rtosc's version struct.
Functions handling messages and arguments.
std::string get_changed_values(const struct Ports &ports, void *runtime)
Return a string list of all changed values.
std::string save_to_file(const struct Ports &ports, void *runtime, const char *appname, rtosc_version appver, std::string file_str="")
Return a savefile containing all values that differ from the default values.
int dispatch_printed_messages(const char *messages, const struct Ports &ports, void *runtime, savefile_dispatcher_t *dispatcher=NULL)
Scan OSC messages from human readable format and dispatch them.
int load_from_file(const char *file_content, const struct Ports &ports, void *runtime, const char *appname, rtosc_version appver, savefile_dispatcher_t *dispatcher=NULL)
Read save file and dispatch contained parameters.
Ports - a dispatchable collection of Port entries.
Definition: ports.h:159
Definition: rtosc.h:86
struct containing an rtosc version
Definition: rtosc-version.h:42