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 
39 namespace rtosc {
40 
54 std::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 
65 protected:
66  enum proceed {
67  abort = -2,
68  discard = -1
69  };
70 
71  enum dependency_t {
72  no_dependencies,
75  };
76 
78  rtosc_curver,
79  app_filever,
80  app_curver;
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 
88 private:
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 
122 int dispatch_printed_messages(const char* messages,
123  const struct Ports& ports, void* runtime,
124  savefile_dispatcher_t *dispatcher = NULL);
125 
134 std::string save_to_file(const struct Ports& ports, void* runtime,
135  const char* appname, rtosc_version appver);
136 
149 int load_from_file(const char* file_content,
150  const struct Ports& ports, void* runtime,
151  const char* appname,
152  rtosc_version appver,
153  savefile_dispatcher_t* dispatcher = NULL);
154 
155 }
156 
157 #endif // RTOSC_SAVEFILE
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.
default values don't depend on others
Definition: savefile.h:73
std::string get_changed_values(const struct Ports &ports, void *runtime)
Return a string list of all changed values.
Definition: rtosc.h:86
default values do depend on others
Definition: savefile.h:74
Ports - a dispatchable collection of Port entries.
Definition: ports.h:157
rtosc_version rtosc_curver
rtosc version of this library
Definition: savefile.h:77
bool operator()(const char *msg)
call this to dispatch a message
Definition: savefile.h:83
the message shall not be dispatched
Definition: savefile.h:68
Definition of rtosc's version struct.
struct containing an rtosc version
Definition: rtosc-version.h:41
dependency_t
Definition: savefile.h:71
proceed
Definition: savefile.h:66
Functions handling messages and arguments.
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.
rtosc_version app_curver
current app version
Definition: savefile.h:77
Class to modify and dispatch messages loaded from savefiles.
Definition: savefile.h:59
rtosc_version app_filever
app version savefile was written with
Definition: savefile.h:77
the message shall lead to abort the savefile loading
Definition: savefile.h:67