File: check_integrity.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 (141 lines) | stat: -rw-r--r-- 3,978 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
/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*
 * LADI Session Handler (ladish)
 *
 * Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
 *
 **************************************************************************
 * This file contains the code that checks data integrity
 **************************************************************************
 *
 * 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 <unistd.h>             /* usleep() */
#include "studio.h"
#include "../proxies/notify_proxy.h"

struct ladish_check_vgraph_integrity_context
{
  ladish_graph_handle jack_graph;
};

static void ladish_check_integrity_fail(const char * message)
{
  log_error("Integirity check failed: %s", message);
  ladish_notify_simple(LADISH_NOTIFY_URGENCY_HIGH, "ladish daemon integrity check failed", LADISH_CHECK_LOG_TEXT);
  usleep(3 * 1000000);
  ASSERT_NO_PASS;
}

#define ctx_ptr ((struct ladish_check_vgraph_integrity_context *)context)

bool
ladish_check_vgraph_integrity_client_begin_callback(
  void * context,
  ladish_graph_handle graph_handle,
  bool hidden,
  ladish_client_handle client_handle,
  const char * client_name,
  void ** client_iteration_context_ptr_ptr)
{
  return true;
}

bool
ladish_check_vgraph_integrity_port_callback(
  void * context,
  ladish_graph_handle vgraph,
  bool hidden,
  void * client_iteration_context_ptr,
  ladish_client_handle client_handle,
  const char * client_name,
  ladish_port_handle vport,
  const char * port_name,
  uint32_t port_type,
  uint32_t port_flags)
{
  uuid_t uuid;
  ladish_port_handle jport;
  char uuid_str[37];
  bool link;

  ladish_port_get_uuid(vport, uuid);
  uuid_unparse(uuid, uuid_str);

  link = ladish_port_is_link(vport);
  if (link)
  {
    return true;
  }

  jport = ladish_graph_find_port_by_uuid(ctx_ptr->jack_graph, uuid, false, vgraph);
  if (jport == NULL)
  {
    log_error("vgraph: %s", ladish_graph_get_description(vgraph));
    log_error("client name: %s", client_name);
    log_error("port name: %s", port_name);
    log_error("port uuid: %s", uuid_str);
    log_error("port ptr: %p", vport);
    log_error("port type: 0x%"PRIX32, port_type);
    log_error("port flags: 0x%"PRIX32, port_flags);
    ladish_check_integrity_fail("vgraph port not found in JACK graph.");
  }

  return true;
}

bool
ladish_check_vgraph_integrity_client_end_callback(
    void * context,
    ladish_graph_handle graph_handle,
    bool hidden,
    ladish_client_handle client_handle,
    const char * client_name,
    void * client_iteration_context_ptr)
{
  return true;
}

#undef ctx_ptr

bool ladish_check_vgraph_integrity(void * context, ladish_graph_handle graph, ladish_app_supervisor_handle app_supervisor)
{
  ladish_graph_iterate_nodes(
    graph,
    context,
    ladish_check_vgraph_integrity_client_begin_callback,
    ladish_check_vgraph_integrity_port_callback,
    ladish_check_vgraph_integrity_client_end_callback);

  return true;
}

void ladish_check_integrity(void)
{
  struct ladish_check_vgraph_integrity_context ctx;

  //ladish_check_integrity_fail("test");

  if (!ladish_studio_is_loaded())
  {
    return;
  }

  ctx.jack_graph = ladish_studio_get_jack_graph();

  ladish_studio_iterate_virtual_graphs(&ctx, ladish_check_vgraph_integrity);
}