| 1 |
/* |
| 2 |
* Copyright (C) 2007 Zeeshan Ali. |
| 3 |
* Copyright (C) 2007 OpenedHand Ltd. |
| 4 |
* Copyright (C) 2013 Jens Georg <[email protected]> |
| 5 |
* |
| 6 |
* Authors: Zeeshan Ali (Khattak) <[email protected]> |
| 7 |
* Jorn Baayen <[email protected]> |
| 8 |
* Jens Georg <[email protected]> |
| 9 |
* |
| 10 |
* This program is free software; you can redistribute it and/or modify |
| 11 |
* it under the terms of the GNU General Public License as published by |
| 12 |
* the Free Software Foundation; either version 2 of the License, or |
| 13 |
* (at your option) any later version. |
| 14 |
* |
| 15 |
* This program is distributed in the hope that it will be useful, |
| 16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
* GNU General Public License for more details. |
| 19 |
* |
| 20 |
* You should have received a copy of the GNU General Public License along |
| 21 |
* with this program; if not, write to the Free Software Foundation, |
| 22 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 23 |
*/ |
| 24 |
|
| 25 |
#include <config.h> |
| 26 |
|
| 27 |
#include <stdio.h> |
| 28 |
#include <locale.h> |
| 29 |
#include <string.h> |
| 30 |
#include <glib/gi18n.h> |
| 31 |
|
| 32 |
#include "gui.h" |
| 33 |
#include "upnp.h" |
| 34 |
#include "main.h" |
| 35 |
|
| 36 |
static gboolean light_status; |
| 37 |
static gint light_load_level; |
| 38 |
|
| 39 |
static int upnp_port = 0; |
| 40 |
static char **interfaces = NULL; |
| 41 |
static char *name = NULL; |
| 42 |
static gboolean exclusive; |
| 43 |
static gboolean ipv4 = TRUE; |
| 44 |
static gboolean ipv6 = TRUE; |
| 45 |
|
| 46 |
// clang-format off |
| 47 |
static GOptionEntry entries[] = |
| 48 |
{ |
| 49 |
{ "port", 'p', 0, G_OPTION_ARG_INT, &upnp_port, N_("Network PORT to use for UPnP"), "PORT" }, |
| 50 |
{ "interface", 'i', 0, G_OPTION_ARG_STRING_ARRAY, &interfaces, N_("Network interfaces to use for UPnP communication"), "INTERFACE" }, |
| 51 |
{ "name", 'n', 0, G_OPTION_ARG_STRING, &name, N_("Friendly name for this UPnP light"), "NAME" }, |
| 52 |
{ "exclusive", 'x', 0, G_OPTION_ARG_NONE, &exclusive, N_("Apply change exclusively to this UPnP light"), NULL }, |
| 53 |
{ "v4", '4', 0, G_OPTION_ARG_NONE, &ipv4, N_("Use IPv4"), NULL }, |
| 54 |
{ "v6", '6', 0, G_OPTION_ARG_NONE, &ipv6, N_("Use IPv6"), NULL }, |
| 55 |
{ "no-v4", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &ipv4, N_("Do not use IPv4"), NULL }, |
| 56 |
{ "no-v6", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &ipv6, N_("Do not use IPv6"), NULL }, |
| 57 |
{ NULL } |
| 58 |
}; |
| 59 |
// clang-format on |
| 60 |
|
| 61 |
void |
| 62 |
set_status (gboolean status) |
| 63 |
{ |
| 64 |
if (status != light_status) { |
| 65 |
light_status = status; |
| 66 |
update_image (); |
| 67 |
|
| 68 |
notify_status_change (status); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
gboolean |
| 73 |
get_status (void) |
| 74 |
{ |
| 75 |
return light_status; |
| 76 |
} |
| 77 |
|
| 78 |
void |
| 79 |
set_load_level (gint load_level) |
| 80 |
{ |
| 81 |
if (load_level != light_load_level) { |
| 82 |
light_load_level = CLAMP (load_level, 0, 100); |
| 83 |
update_image (); |
| 84 |
|
| 85 |
notify_load_level_change (light_load_level); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
gint |
| 90 |
get_load_level (void) |
| 91 |
{ |
| 92 |
return light_load_level; |
| 93 |
} |
| 94 |
|
| 95 |
int |
| 96 |
main (int argc, char **argv) |
| 97 |
{ |
| 98 |
GError *error = NULL; |
| 99 |
GOptionContext *context = NULL; |
| 100 |
|
| 101 |
/* Light is off in the beginning */ |
| 102 |
light_status = FALSE; |
| 103 |
light_load_level = 100; |
| 104 |
|
| 105 |
setlocale (LC_ALL, ""); |
| 106 |
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); |
| 107 |
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
| 108 |
textdomain (GETTEXT_PACKAGE); |
| 109 |
|
| 110 |
context = g_option_context_new (_("- UPnP AV control point")); |
| 111 |
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); |
| 112 |
g_option_context_add_group (context, gtk_get_option_group (TRUE)); |
| 113 |
|
| 114 |
if (!g_option_context_parse (context, &argc, &argv, &error)) { |
| 115 |
g_print (_("Could not parse options: %s\n"), error->message); |
| 116 |
|
| 117 |
g_option_context_free (context); |
| 118 |
|
| 119 |
return -4; |
| 120 |
} |
| 121 |
|
| 122 |
g_option_context_free (context); |
| 123 |
|
| 124 |
if (!init_ui (&argc, &argv, name, exclusive)) { |
| 125 |
return -1; |
| 126 |
} |
| 127 |
|
| 128 |
if (!init_upnp (interfaces, upnp_port, name, ipv4, ipv6)) { |
| 129 |
return -2; |
| 130 |
} |
| 131 |
|
| 132 |
gtk_main (); |
| 133 |
|
| 134 |
deinit_ui (); |
| 135 |
deinit_upnp (); |
| 136 |
|
| 137 |
return 0; |
| 138 |
} |