File: control.c

package info (click to toggle)
ladish 1%2Bdfsg0-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,940 kB
  • sloc: ansic: 36,406; python: 11,237; cpp: 705; makefile: 22; ruby: 20; sh: 17
file content (182 lines) | stat: -rw-r--r-- 4,258 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*
 * LADI Session Handler (ladish)
 *
 * Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
 *
 **************************************************************************
 * This file contains code related to the ladishd control object
 **************************************************************************
 *
 * LADI Session Handler is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * LADI Session Handler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
 * or write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "internal.h"
#include "studio.h"
#include "../proxies/control_proxy.h"
#include "../proxies/studio_proxy.h"
#include "world_tree.h"
#include "ask_dialog.h"

static guint g_ladishd_poll_source_tag;

static gboolean poll_ladishd(gpointer data)
{
  control_proxy_ping();
  return TRUE;
}

void control_proxy_on_daemon_appeared(void)
{
  if (get_studio_state() == STUDIO_STATE_NA || get_studio_state() == STUDIO_STATE_SICK)
  {
    log_info("ladishd appeared");
    g_source_remove(g_ladishd_poll_source_tag);
  }

  set_studio_state(STUDIO_STATE_UNLOADED);
  studio_state_changed(NULL);
}

void control_proxy_on_daemon_disappeared(bool clean_exit)
{
  log_info("ladishd disappeared");

  if (!clean_exit)
  {
    error_message_box("ladish daemon crashed");
    set_studio_state(STUDIO_STATE_SICK);
  }
  else
  {
    set_studio_state(STUDIO_STATE_NA);
  }

  studio_state_changed(NULL);

  if (studio_loaded())
  {
    destroy_studio_view();
  }

  world_tree_destroy_room_views();

  g_ladishd_poll_source_tag = g_timeout_add(500, poll_ladishd, NULL);
}

void control_proxy_on_studio_appeared(bool initial)
{
  char * name;
  bool started;

  set_studio_state(STUDIO_STATE_STOPPED);

  if (initial)
  {
    if (!studio_proxy_is_started(&started))
    {
      log_error("intially, studio is present but is_started() check failed.");
      return;
    }

    if (started)
    {
      set_studio_state(STUDIO_STATE_STARTED);
    }
  }

  if (studio_state_changed(&name))
  {
    if (studio_loaded())
    {
      log_error("studio appear signal received but studio already exists");
    }
    else
    {
      create_studio_view(name);
    }

    free(name);
  }
}

void control_proxy_on_studio_disappeared(void)
{
  set_studio_state(STUDIO_STATE_UNLOADED);
  studio_state_changed(NULL);

  if (!studio_loaded())
  {
    log_error("studio disappear signal received but studio does not exists");
    return;
  }

  destroy_studio_view();
}

void menu_request_ladishd_exit(void)
{
  log_info("ladishd exit request");

  if (!control_proxy_exit())
  {
    error_message_box(_("ladishd exit command failed, please inspect logs."));
  }
}

void menu_request_new_studio(void)
{
  char * new_name;

  log_info("new studio request");

  if (name_dialog(_("New studio"), _("Studio name"), "", &new_name))
  {
    if (!control_proxy_new_studio(new_name))
    {
      error_message_box(_("Creation of new studio failed, please inspect logs."));
    }

    free(new_name);
  }
}

void on_load_studio(const char * studio_name)
{
  log_info("Load studio \"%s\"", studio_name);

  if (!control_proxy_load_studio(studio_name))
  {
    error_message_box(_("Studio load failed, please inspect logs."));
  }
}

void on_delete_studio(const char * studio_name)
{
  bool result;

  if (!ask_dialog(&result, _("<b><big>Confirm studio delete</big></b>"), _("Studio \"%s\" will be deleted. Are you sure?"), studio_name) || !result)
  {
    return;
  }

  log_info("Delete studio \"%s\"", studio_name);

  if (!control_proxy_delete_studio(studio_name))
  {
    error_message_box(_("Studio delete failed, please inspect logs."));
  }
}