PageRenderTime 25ms CodeModel.GetById 13ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/src/bdrcfg.c

http://bdremote-ng.googlecode.com/
C | 255 lines | 188 code | 36 blank | 31 comment | 32 complexity | 3f809f84c4d8796c14408d29bbfc8434 MD5 | raw file
  1/*
  2 *  bdremoteng - helper daemon for Sony(R) BD Remote Control
  3 *  Based on bdremoted, written by Anton Starikov <antst@mail.ru>.
  4 *
  5 *  Copyright (C) 2009  Michael Wojciechowski <wojci@wojci.dk>
  6 *
  7 *
  8 *  This program is free software; you can redistribute it and/or modify
  9 *  it under the terms of the GNU General Public License as published by
 10 *  the Free Software Foundation; either version 2 of the License, or
 11 *  (at your option) any later version.
 12 *
 13 *  This program is distributed in the hope that it will be useful,
 14 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 *  GNU General Public License for more details.
 17 *
 18 *  You should have received a copy of the GNU General Public License
 19 *  along with this program; if not, write to the Free Software
 20 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 21 *
 22 */
 23
 24/** \ingroup Gen
 25 *  @{
 26 */
 27
 28/*! \file bdrcfg.c
 29  \brief Implements functions for handling configuration.
 30
 31  Implements a few functions used to set certain config keys.
 32*/
 33
 34#include "bdrcfg.h"
 35
 36#include <stdlib.h>
 37#include <string.h>
 38#include <stdio.h>
 39#include <assert.h>
 40#include <globaldefs.h>
 41
 42void setDefaults(configuration* _config)
 43{
 44  assert(_config != NULL);
 45
 46  _config->listen_port = 8888;
 47  _config->disconnect_timeout = 60;
 48  _config->repeat_rate  = 10;
 49  _config->repeat_delay = 200;
 50  _config->debug       = 0;
 51  _config->interface_addr_set = 0;
 52  FREEVAL(_config->interface_addr);
 53  FREEVAL(_config->remote_addr);
 54  _config->remote_addr = NULL;
 55  _config->detach      = 1;
 56  FREEVAL(_config->release);
 57  _config->lirc_namespace = 0;
 58  _config->release     = NULL;
 59  _config->event_out = 0;
 60  FREEVAL(_config->user);
 61  _config->user        = NULL;
 62  FREEVAL(_config->group);
 63  _config->group       = NULL;
 64  _config->log_filename_set = 0;
 65  FREEVAL(_config->log_filename);
 66  _config->log_filename = NULL;
 67  _config->battery_script_set = 0;
 68  FREEVAL(_config->battery_script);
 69  _config->battery_script = NULL;
 70}
 71
 72void setRemoteAddress(configuration* _config, const char* _address)
 73{
 74  assert(_config != NULL);
 75  assert(_address != NULL);
 76
 77  SETVAL(_config->remote_addr, _address);
 78}
 79
 80void setInterfaceAddress(configuration* _config, const char* _address)
 81{
 82  assert(_config != NULL);
 83  assert(_address != NULL);
 84
 85  SETVAL(_config->interface_addr, _address);
 86  _config->interface_addr_set = 1;
 87}
 88
 89void setRelease(configuration* _config, const char* _release)
 90{
 91  assert(_config != NULL);
 92  assert(_release != NULL);
 93
 94  SETVAL(_config->release, _release);
 95}
 96
 97void setUser(configuration* _config, const char* _user)
 98{
 99  assert(_config != NULL);
100  assert(_user != NULL);
101
102  SETVAL(_config->user, _user);
103}
104
105void setGroup(configuration* _config, const char* _group)
106{
107  assert(_config != NULL);
108  assert(_group != NULL);
109
110  SETVAL(_config->group, _group);
111}
112
113void setBatteryScript(configuration* _config, const char* _script)
114{
115   assert(_config != NULL);
116   assert(_script != NULL);
117
118   SETVAL(_config->battery_script, _script);
119   _config->battery_script_set = 1;
120}
121
122void destroyConfig(configuration* _config)
123{
124  assert(_config != NULL);
125
126  FREEVAL(_config->remote_addr);
127  FREEVAL(_config->release);
128  FREEVAL(_config->user);
129  FREEVAL(_config->group);
130  FREEVAL(_config->log_filename);
131  FREEVAL(_config->battery_script);
132}
133
134void printConfig(const configuration* _config)
135{
136  assert(_config != NULL);
137
138  fprintf(printStream, "Configuration:\n");
139  fprintf(printStream, " - listen port : %d.\n", _config->listen_port);
140  fprintf(printStream, " - timeout     : %d second(s).\n", _config->disconnect_timeout);
141#if ENABLE_REPEAT
142  fprintf(printStream, " - repeat rate : %d per secound.\n", _config->repeat_rate);
143  fprintf(printStream, " - repeat delay: %d ms.\n", _config->repeat_delay);
144#else
145  fprintf(printStream, " - repeat rate : disabled.\n");
146  fprintf(printStream, " - repeat delay: disabled.\n");
147#endif
148  if (_config->release == NULL)
149    {
150      fprintf(printStream, " - release     : not set.\n");
151    }
152  else
153    {
154      fprintf(printStream, " - release     : %s.\n", _config->release);
155    }
156  fprintf(printStream, " - LIRC names  : %d.\n", _config->lirc_namespace);
157  fprintf(printStream, " - event output: %d.\n", _config->event_out);
158  fprintf(printStream, " - debug       : %d.\n", _config->debug);
159  if (_config->debug)
160    {
161      fprintf(printStream, "                 LIRC thread(%u) sock(%u) callback(%u),\n",
162	      BDREMOTE_MASKCHECK(MODULEMASK_LIRC_THR),
163	      BDREMOTE_MASKCHECK(MODULEMASK_LIRC_SOCK),
164	      BDREMOTE_MASKCHECK(MODULEMASK_LIRC_CB));
165
166      fprintf(printStream, "                 bluetooth interface(%u) implementation(%u),\n",
167	      BDREMOTE_MASKCHECK(MODULEMASK_BT_IF),
168	      BDREMOTE_MASKCHECK(MODULEMASK_BT_IMPL));
169 
170      fprintf(printStream, "                 queue(%u),\n", 
171	      BDREMOTE_MASKCHECK(MODULEMASK_QUEUE));
172
173      fprintf(printStream, "                 spare(%u),\n", 
174	      BDREMOTE_MASKCHECK(MODULEMASK_SPARE));
175
176      fprintf(printStream, "                 main(%u).\n", 
177	      BDREMOTE_MASKCHECK(MODULEMASK_MAIN));
178
179    }
180
181  if (_config->interface_addr_set)
182    {
183      fprintf(printStream, " - iface addr  : %s.\n", _config->interface_addr);
184    }
185  else
186    {
187      fprintf(printStream, " - iface addr  : ANY.\n");
188    }
189
190  fprintf(printStream, " - remote addr : %s.\n", _config->remote_addr);
191  fprintf(printStream, " - detach      : %d.\n", _config->detach);
192  if (_config->user == NULL)
193    {
194      fprintf(printStream, " - user        : not set.\n");
195    }
196  else
197    {
198      fprintf(printStream, " - user        : %s.\n", _config->user);
199    }
200  if (_config->group == NULL)
201    {
202      fprintf(printStream, " - group       : not set.\n");
203    }
204  else
205    {
206      fprintf(printStream, " - group       : %s.\n", _config->group);
207    }
208  if (_config->log_filename_set)
209    {
210      fprintf(printStream, " - log         : '%s'.\n", _config->log_filename);
211    }
212  else
213    {
214      fprintf(printStream, " - log         : stdout.\n");
215    }
216  if (_config->battery_script_set)
217     {
218        fprintf(printStream, " - battery\n");
219        fprintf(printStream, " - script    : '%s'.\n", _config->battery_script);
220     }
221  else
222     {
223        fprintf(printStream, " - battery\n");
224        fprintf(printStream, " - script    : not set.\n");
225     }
226}
227
228int userAndGroupSet(const configuration* _config)
229{
230  int status = 1;
231  assert(_config != NULL);
232
233  if (_config->user == NULL)
234    {
235      status = 0;
236    }
237  if (_config->group == NULL)
238    {
239      status = 0;
240    }
241
242  return status;
243}
244
245void setLogFilename(configuration* _config, const char* _filename)
246{
247  assert(_config != NULL);
248  assert(_filename != NULL);
249
250  SETVAL(_config->log_filename, _filename);
251  _config->log_filename_set = 1;
252}
253
254/*@}*/
255