Ardour  9.0-pre0-582-g084a23a80d
nsmclient.h
Go to the documentation of this file.
1 
2 /*******************************************************************************/
3 /* Copyright (C) 2012 Jonathan Moore Liles */
4 /* */
5 /* This program is free software; you can redistribute it and/or modify it */
6 /* under the terms of the GNU General Public License as published by the */
7 /* Free Software Foundation; either version 2 of the License, or (at your */
8 /* option) any later version. */
9 /* */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
12 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
13 /* more details. */
14 /* */
15 /* You should have received a copy of the GNU General Public License along */
16 /* with This program; see the file COPYING. If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /*******************************************************************************/
19 
20 #pragma once
21 
22 #include <lo/lo.h>
23 
24 namespace NSM
25 {
26 class Client
27 {
28 private:
29 
30  const char *nsm_url;
31 
32  lo_server _server;
33  lo_server_thread _st;
34  lo_address nsm_addr;
35 
40 
41 public:
42 
43  enum
44  {
45  ERR_OK = 0,
53  ERR_NOT_NOW = -8
54  };
55 
56  Client ();
57  virtual ~Client ();
58 
59  bool is_active (void) { return nsm_is_active; }
60 
61  const char *session_manager_name (void) { return _session_manager_name; }
62  const char *client_id (void) { return _nsm_client_id; }
63  const char *client_path (void) { return _nsm_client_path; }
64 
65  /* Client->Server methods */
66  void is_dirty (void);
67  void is_clean (void);
68  void progress (float f);
69  void message (int priority, const char *msg);
70  void announce (const char *appliction_name, const char *capabilities, const char *process_name);
71 
72  void broadcast (lo_message msg);
73 
74  /* init without threading */
75  int init (const char *nsm_url);
76  /* init with threading */
77  int init_thread (const char *nsm_url);
78 
79  /* call this periodically to check for new messages */
80  void check (int timeout = 0);
81 
82  /* or call these to start and stop a thread (must do your own locking in handler!) */
83  void start (void);
84  void stop (void);
85 
86 protected:
87 
88  /* Server->Client methods */
89  virtual int command_open (const char *name, const char *display_name, const char *client_id, char **out_msg) = 0;
90  virtual int command_save (char **out_msg) = 0;
91 
92  virtual void command_active (bool) {}
93 
94  virtual void command_session_is_loaded (void) {}
95 
96  /* invoked when an unrecognized message is received. Should return 0 if you handled it, -1 otherwise. */
97  virtual int command_broadcast (const char *, lo_message) { return -1; }
98 
99 private:
100 
101  /* osc handlers */
102  static int osc_open (const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data);
103  static int osc_save (const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data);
104  static int osc_announce_reply (const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data);
105  static int osc_error (const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data);
106  static int osc_session_is_loaded (const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data);
107  static int osc_broadcast (const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data);
108 
109 };
110 };
lo_address nsm_addr
Definition: nsmclient.h:34
char * _nsm_client_path
Definition: nsmclient.h:39
void progress(float f)
void broadcast(lo_message msg)
int init_thread(const char *nsm_url)
bool is_active(void)
Definition: nsmclient.h:59
const char * client_id(void)
Definition: nsmclient.h:62
const char * session_manager_name(void)
Definition: nsmclient.h:61
static int osc_broadcast(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data)
int init(const char *nsm_url)
static int osc_save(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data)
void is_clean(void)
void is_dirty(void)
void stop(void)
bool nsm_is_active
Definition: nsmclient.h:36
char * _session_manager_name
Definition: nsmclient.h:38
static int osc_open(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data)
@ ERR_NO_SESSION_OPEN
Definition: nsmclient.h:51
@ ERR_NO_SUCH_FILE
Definition: nsmclient.h:50
@ ERR_UNSAVED_CHANGES
Definition: nsmclient.h:52
@ ERR_INCOMPATIBLE_API
Definition: nsmclient.h:47
@ ERR_BLACKLISTED
Definition: nsmclient.h:48
@ ERR_LAUNCH_FAILED
Definition: nsmclient.h:49
virtual ~Client()
virtual void command_session_is_loaded(void)
Definition: nsmclient.h:94
void message(int priority, const char *msg)
static int osc_announce_reply(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data)
void start(void)
virtual void command_active(bool)
Definition: nsmclient.h:92
lo_server_thread _st
Definition: nsmclient.h:33
virtual int command_broadcast(const char *, lo_message)
Definition: nsmclient.h:97
virtual int command_save(char **out_msg)=0
virtual int command_open(const char *name, const char *display_name, const char *client_id, char **out_msg)=0
static int osc_session_is_loaded(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data)
void announce(const char *appliction_name, const char *capabilities, const char *process_name)
const char * nsm_url
Definition: nsmclient.h:30
void check(int timeout=0)
static int osc_error(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data)
lo_server _server
Definition: nsmclient.h:32
const char * client_path(void)
Definition: nsmclient.h:63
char * _nsm_client_id
Definition: nsmclient.h:37
GtkImageIconNameData name
Definition: gtkimage.h:6
Definition: nsmclient.h:25