| 1 |
/* |
|---|
| 2 |
* Copyright (C) 2005-2008 by Pieter Palmers |
|---|
| 3 |
* |
|---|
| 4 |
* This file is part of FFADO |
|---|
| 5 |
* FFADO = Free Firewire (pro-)audio drivers for linux |
|---|
| 6 |
* |
|---|
| 7 |
* FFADO is based upon FreeBoB |
|---|
| 8 |
* |
|---|
| 9 |
* This program is free software: you can redistribute it and/or modify |
|---|
| 10 |
* it under the terms of the GNU General Public License as published by |
|---|
| 11 |
* the Free Software Foundation, either version 2 of the License, or |
|---|
| 12 |
* (at your option) version 3 of the License. |
|---|
| 13 |
* |
|---|
| 14 |
* This program is distributed in the hope that it will be useful, |
|---|
| 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 |
* GNU General Public License for more details. |
|---|
| 18 |
* |
|---|
| 19 |
* You should have received a copy of the GNU General Public License |
|---|
| 20 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 21 |
* |
|---|
| 22 |
*/ |
|---|
| 23 |
|
|---|
| 24 |
#include <argp.h> |
|---|
| 25 |
#include <stdlib.h> |
|---|
| 26 |
#include <iostream> |
|---|
| 27 |
#include <signal.h> |
|---|
| 28 |
|
|---|
| 29 |
#include "controlserver.h" |
|---|
| 30 |
|
|---|
| 31 |
using namespace std; |
|---|
| 32 |
|
|---|
| 33 |
DECLARE_GLOBAL_DEBUG_MODULE; |
|---|
| 34 |
|
|---|
| 35 |
//////////////////////////////////////////////// |
|---|
| 36 |
// arg parsing |
|---|
| 37 |
//////////////////////////////////////////////// |
|---|
| 38 |
const char *argp_program_version = "test-dbus-server 0.1"; |
|---|
| 39 |
const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>"; |
|---|
| 40 |
static char doc[] = "test-dbus-server -- test server for the DBUS interface"; |
|---|
| 41 |
static char args_doc[] = ""; |
|---|
| 42 |
static struct argp_option options[] = { |
|---|
| 43 |
{"verbose", 'v', 0, 0, "Produce verbose output" }, |
|---|
| 44 |
{ 0 } |
|---|
| 45 |
}; |
|---|
| 46 |
|
|---|
| 47 |
struct arguments |
|---|
| 48 |
{ |
|---|
| 49 |
arguments() |
|---|
| 50 |
: verbose( false ) |
|---|
| 51 |
{ |
|---|
| 52 |
args[0] = 0; |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
char* args[50]; |
|---|
| 56 |
bool verbose; |
|---|
| 57 |
} arguments; |
|---|
| 58 |
|
|---|
| 59 |
// Parse a single option. |
|---|
| 60 |
static error_t |
|---|
| 61 |
parse_opt( int key, char* arg, struct argp_state* state ) |
|---|
| 62 |
{ |
|---|
| 63 |
// Get the input argument from `argp_parse', which we |
|---|
| 64 |
// know is a pointer to our arguments structure. |
|---|
| 65 |
struct arguments* arguments = ( struct arguments* ) state->input; |
|---|
| 66 |
|
|---|
| 67 |
// char* tail; |
|---|
| 68 |
switch (key) { |
|---|
| 69 |
case 'v': |
|---|
| 70 |
arguments->verbose = true; |
|---|
| 71 |
break; |
|---|
| 72 |
case ARGP_KEY_ARG: |
|---|
| 73 |
if (state->arg_num >= 50) { |
|---|
| 74 |
// Too many arguments. |
|---|
| 75 |
argp_usage (state); |
|---|
| 76 |
} |
|---|
| 77 |
arguments->args[state->arg_num] = arg; |
|---|
| 78 |
break; |
|---|
| 79 |
case ARGP_KEY_END: |
|---|
| 80 |
break; |
|---|
| 81 |
default: |
|---|
| 82 |
return ARGP_ERR_UNKNOWN; |
|---|
| 83 |
} |
|---|
| 84 |
return 0; |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
static struct argp argp = { options, parse_opt, args_doc, doc }; |
|---|
| 88 |
|
|---|
| 89 |
/////////////////////////// |
|---|
| 90 |
// main |
|---|
| 91 |
////////////////////////// |
|---|
| 92 |
|
|---|
| 93 |
DBus::BusDispatcher dispatcher; |
|---|
| 94 |
|
|---|
| 95 |
void leave( int sig ) |
|---|
| 96 |
{ |
|---|
| 97 |
dispatcher.leave(); |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
static const char* SERVER_NAME = "org.ffado.Control"; |
|---|
| 101 |
|
|---|
| 102 |
void start_server() { |
|---|
| 103 |
|
|---|
| 104 |
// test DBUS stuff |
|---|
| 105 |
DBus::default_dispatcher = &dispatcher; |
|---|
| 106 |
|
|---|
| 107 |
DBus::Connection conn = DBus::Connection::SessionBus(); |
|---|
| 108 |
conn.request_name(SERVER_NAME); |
|---|
| 109 |
|
|---|
| 110 |
// Control::Continuous c0("test0"); |
|---|
| 111 |
// c0.setVerboseLevel(DEBUG_LEVEL_VERBOSE); |
|---|
| 112 |
// DBusControl::Continuous fader(conn, "/org/ffado/Control/Test/Fader", c0); |
|---|
| 113 |
// |
|---|
| 114 |
Control::Container cont(NULL, "container1"); |
|---|
| 115 |
cont.setVerboseLevel(DEBUG_LEVEL_VERBOSE); |
|---|
| 116 |
// |
|---|
| 117 |
// Control::Container cont1("container2"); |
|---|
| 118 |
// cont1.setVerboseLevel(DEBUG_LEVEL_VERBOSE); |
|---|
| 119 |
// |
|---|
| 120 |
// cont.addElement(&cont1); |
|---|
| 121 |
// |
|---|
| 122 |
// Control::Continuous c1("test1"); |
|---|
| 123 |
// c1.setVerboseLevel(DEBUG_LEVEL_VERBOSE); |
|---|
| 124 |
// cont.addElement(&c1); |
|---|
| 125 |
// |
|---|
| 126 |
// Control::Continuous c2("test2"); |
|---|
| 127 |
// c2.setVerboseLevel(DEBUG_LEVEL_VERBOSE); |
|---|
| 128 |
// cont.addElement(&c2); |
|---|
| 129 |
// |
|---|
| 130 |
// Control::Continuous c3("test3"); |
|---|
| 131 |
// c3.setVerboseLevel(DEBUG_LEVEL_VERBOSE); |
|---|
| 132 |
// cont.addElement(&c3); |
|---|
| 133 |
// |
|---|
| 134 |
// Control::Continuous c4("test4"); |
|---|
| 135 |
// c4.setVerboseLevel(DEBUG_LEVEL_VERBOSE); |
|---|
| 136 |
// cont1.addElement(&c4); |
|---|
| 137 |
// |
|---|
| 138 |
// Control::Continuous c5("test5"); |
|---|
| 139 |
// c5.setVerboseLevel(DEBUG_LEVEL_VERBOSE); |
|---|
| 140 |
// cont1.addElement(&c5); |
|---|
| 141 |
// |
|---|
| 142 |
// Control::Discrete d1("test_discr1"); |
|---|
| 143 |
// d1.setVerboseLevel(DEBUG_LEVEL_VERBOSE); |
|---|
| 144 |
// cont1.addElement(&d1); |
|---|
| 145 |
// |
|---|
| 146 |
// Control::Enum e1("test_enum"); |
|---|
| 147 |
// e1.setVerboseLevel(DEBUG_LEVEL_VERBOSE); |
|---|
| 148 |
// cont1.addElement(&e1); |
|---|
| 149 |
// |
|---|
| 150 |
// Control::AttributeEnum a1("test_attrenum"); |
|---|
| 151 |
// a1.setVerboseLevel(DEBUG_LEVEL_VERBOSE); |
|---|
| 152 |
// cont1.addElement(&a1); |
|---|
| 153 |
// |
|---|
| 154 |
// Control::Text t1("test_text"); |
|---|
| 155 |
// t1.setVerboseLevel(DEBUG_LEVEL_VERBOSE); |
|---|
| 156 |
// cont1.addElement(&t1); |
|---|
| 157 |
|
|---|
| 158 |
// Note: create handlers AFTER all children are added |
|---|
| 159 |
|
|---|
| 160 |
// we do dynamic allocation such that we are sure |
|---|
| 161 |
// the container is deleted before the children become invalid |
|---|
| 162 |
DBusControl::Container *container |
|---|
| 163 |
= new DBusControl::Container(conn, "/org/ffado/Control/Test/Container", NULL, cont); |
|---|
| 164 |
|
|---|
| 165 |
dispatcher.enter(); |
|---|
| 166 |
|
|---|
| 167 |
delete container; |
|---|
| 168 |
|
|---|
| 169 |
} |
|---|
| 170 |
|
|---|
| 171 |
int |
|---|
| 172 |
main(int argc, char **argv) |
|---|
| 173 |
{ |
|---|
| 174 |
signal(SIGTERM, leave); |
|---|
| 175 |
signal(SIGINT, leave); |
|---|
| 176 |
|
|---|
| 177 |
setDebugLevel(DEBUG_LEVEL_VERBOSE); |
|---|
| 178 |
|
|---|
| 179 |
// arg parsing |
|---|
| 180 |
argp_parse (&argp, argc, argv, 0, 0, &arguments); |
|---|
| 181 |
|
|---|
| 182 |
errno = 0; |
|---|
| 183 |
// char* tail; |
|---|
| 184 |
|
|---|
| 185 |
if (errno) { |
|---|
| 186 |
perror("argument parsing failed:"); |
|---|
| 187 |
return -1; |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
debugOutput(DEBUG_LEVEL_NORMAL, "DBUS test server\n"); |
|---|
| 191 |
|
|---|
| 192 |
DBus::_init_threading(); |
|---|
| 193 |
|
|---|
| 194 |
start_server(); |
|---|
| 195 |
|
|---|
| 196 |
debugOutput(DEBUG_LEVEL_NORMAL, "bye...\n"); |
|---|
| 197 |
|
|---|
| 198 |
return 0; |
|---|
| 199 |
} |
|---|