Merge branch 'stable' into 'main'
[ladish.git] / daemon / check_integrity.c
blobde15078b752db39116c0106d8ce7fcda195456ec
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2010,2012 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains the code that checks data integrity
9 **************************************************************************
11 * LADI Session Handler is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * LADI Session Handler is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 * or write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <unistd.h> /* usleep() */
28 #include "studio.h"
29 #include "../proxies/notify_proxy.h"
31 struct ladish_check_vgraph_integrity_context
33 ladish_graph_handle jack_graph;
36 static void ladish_check_integrity_fail(const char * message)
38 log_error("Integirity check failed: %s", message);
39 ladish_notify_simple(LADISH_NOTIFY_URGENCY_HIGH, "ladish daemon integrity check failed", LADISH_CHECK_LOG_TEXT);
40 usleep(3 * 1000000);
41 ASSERT_NO_PASS;
44 #define ctx_ptr ((struct ladish_check_vgraph_integrity_context *)context)
46 bool
47 ladish_check_vgraph_integrity_client_begin_callback(
48 void * UNUSED(context),
49 ladish_graph_handle UNUSED(graph_handle),
50 bool UNUSED(hidden),
51 ladish_client_handle UNUSED(client_handle),
52 const char * UNUSED(client_name),
53 void ** UNUSED(client_iteration_context_ptr_ptr))
55 return true;
58 bool
59 ladish_check_vgraph_integrity_port_callback(
60 void * context,
61 ladish_graph_handle vgraph,
62 bool UNUSED(hidden),
63 void * UNUSED(client_iteration_context_ptr),
64 ladish_client_handle UNUSED(client_handle),
65 const char * client_name,
66 ladish_port_handle vport,
67 const char * port_name,
68 uint32_t port_type,
69 uint32_t port_flags)
71 uuid_t uuid;
72 ladish_port_handle jport;
73 char uuid_str[37];
74 bool link;
76 ladish_port_get_uuid(vport, uuid);
77 uuid_unparse(uuid, uuid_str);
79 link = ladish_port_is_link(vport);
80 if (link)
82 return true;
85 jport = ladish_graph_find_port_by_uuid(ctx_ptr->jack_graph, uuid, false, vgraph);
86 if (jport == NULL)
88 log_error("vgraph: %s", ladish_graph_get_description(vgraph));
89 log_error("client name: %s", client_name);
90 log_error("port name: %s", port_name);
91 log_error("port uuid: %s", uuid_str);
92 log_error("port ptr: %p", vport);
93 log_error("port type: 0x%"PRIX32, port_type);
94 log_error("port flags: 0x%"PRIX32, port_flags);
95 ladish_check_integrity_fail("vgraph port not found in JACK graph.");
98 return true;
101 bool
102 ladish_check_vgraph_integrity_client_end_callback(
103 void * UNUSED(context),
104 ladish_graph_handle UNUSED(graph_handle),
105 bool UNUSED(hidden),
106 ladish_client_handle UNUSED(client_handle),
107 const char * UNUSED(client_name),
108 void * UNUSED(client_iteration_context_ptr))
110 return true;
113 #undef ctx_ptr
115 bool
116 ladish_check_vgraph_integrity(
117 void * context,
118 ladish_graph_handle graph,
119 ladish_app_supervisor_handle UNUSED(app_supervisor))
121 ladish_graph_iterate_nodes(
122 graph,
123 context,
124 ladish_check_vgraph_integrity_client_begin_callback,
125 ladish_check_vgraph_integrity_port_callback,
126 ladish_check_vgraph_integrity_client_end_callback);
128 return true;
131 void ladish_check_integrity(void)
133 struct ladish_check_vgraph_integrity_context ctx;
135 //ladish_check_integrity_fail("test");
137 if (!ladish_studio_is_loaded())
139 return;
142 ctx.jack_graph = ladish_studio_get_jack_graph();
144 ladish_studio_iterate_virtual_graphs(&ctx, ladish_check_vgraph_integrity);