ardour
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 
27  class Client
28  {
29 
30  private:
31 
32  const char *nsm_url;
33 
34  lo_server _server;
35  lo_server_thread _st;
36  lo_address nsm_addr;
37 
42 
43  public:
44 
45  enum
46  {
47  ERR_OK = 0,
56  };
57 
58  Client ( );
59  virtual ~Client ( );
60 
61  bool is_active ( void ) { return nsm_is_active; }
62 
63  const char *session_manager_name ( void ) { return _session_manager_name; }
64  const char *client_id ( void ) { return _nsm_client_id; }
65  const char *client_path ( void ) { return _nsm_client_path; }
66 
67  /* Client->Server methods */
68  void is_dirty ( void );
69  void is_clean ( void );
70  void progress ( float f );
71  void message( int priority, const char *msg );
72  void announce ( const char *appliction_name, const char *capabilities, const char *process_name );
73 
74  void broadcast ( lo_message msg );
75 
76  /* init without threading */
77  int init ( const char *nsm_url );
78  /* init with threading */
79  int init_thread ( const char *nsm_url );
80 
81  /* call this periodically to check for new messages */
82  void check ( int timeout = 0 );
83 
84  /* or call these to start and stop a thread (must do your own locking in handler!) */
85  void start ( void );
86  void stop ( void );
87 
88  protected:
89 
90  /* Server->Client methods */
91  virtual int command_open ( const char *name, const char *display_name, const char *client_id, char **out_msg ) = 0;
92  virtual int command_save ( char **out_msg ) = 0;
93 
94  virtual void command_active ( bool ) { }
95 
96  virtual void command_session_is_loaded ( void ) { }
97 
98  /* invoked when an unrecognized message is received. Should return 0 if you handled it, -1 otherwise. */
99  virtual int command_broadcast ( const char *, lo_message ) { return -1; }
100 
101  private:
102 
103  /* osc handlers */
104  static int osc_open ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data );
105  static int osc_save ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data );
106  static int osc_announce_reply ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data );
107  static int osc_error ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data );
108  static int osc_session_is_loaded ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data );
109  static int osc_broadcast ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data );
110 
111  };
112 };
void is_clean(void)
Definition: nsmclient.cc:116
char * _session_manager_name
Definition: nsmclient.h:40
virtual int command_open(const char *name, const char *display_name, const char *client_id, char **out_msg)=0
static int osc_broadcast(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data)
Definition: nsmclient.cc:216
void announce(const char *appliction_name, const char *capabilities, const char *process_name)
Definition: nsmclient.cc:74
void message(int priority, const char *msg)
Definition: nsmclient.cc:125
const char * client_id(void)
Definition: nsmclient.h:64
void stop(void)
Definition: nsmclient.cc:157
virtual void command_active(bool)
Definition: nsmclient.h:94
static int osc_open(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data)
Definition: nsmclient.cc:240
bool is_active(void)
Definition: nsmclient.h:61
lo_server_thread _st
Definition: nsmclient.h:35
tuple f
Definition: signals.py:35
virtual int command_save(char **out_msg)=0
const char * nsm_url
Definition: nsmclient.h:32
static int osc_session_is_loaded(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data)
Definition: nsmclient.cc:263
static int osc_error(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data)
Definition: nsmclient.cc:273
char * _nsm_client_id
Definition: nsmclient.h:39
void check(int timeout=0)
Definition: nsmclient.cc:144
virtual void command_session_is_loaded(void)
Definition: nsmclient.h:96
bool nsm_is_active
Definition: nsmclient.h:38
lo_address nsm_addr
Definition: nsmclient.h:36
virtual int command_broadcast(const char *, lo_message)
Definition: nsmclient.h:99
int init(const char *nsm_url)
Definition: nsmclient.cc:163
static int osc_save(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data)
Definition: nsmclient.cc:222
virtual ~Client()
Definition: nsmclient.cc:62
lo_server _server
Definition: nsmclient.h:34
const char * name
void progress(float f)
Definition: nsmclient.cc:98
void start(void)
Definition: nsmclient.cc:151
const char * client_path(void)
Definition: nsmclient.h:65
void broadcast(lo_message msg)
Definition: nsmclient.cc:135
int init_thread(const char *nsm_url)
Definition: nsmclient.cc:187
static int osc_announce_reply(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data)
Definition: nsmclient.cc:289
Definition: nsmclient.cc:36
void is_dirty(void)
Definition: nsmclient.cc:107
char * _nsm_client_path
Definition: nsmclient.h:41
const char * session_manager_name(void)
Definition: nsmclient.h:63