remove use of implicit namespaces
[ladish.git] / gui / lash_proxy.cpp
blob497768c66f4ec5b7f6c6cc2024ac5515de28f7b2
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2008 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains code that communicates with ladishd through D-Bus
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 "common.h"
29 #include <string.h>
30 #include <dbus/dbus.h>
32 #include "lash_proxy.hpp"
33 #include "session.hpp"
34 #include "project.hpp"
35 #include "lash_client.hpp"
36 #include "globals.hpp"
37 #include "dbus_helpers.h"
39 #define LASH_SERVICE DBUS_NAME_BASE
40 #define LASH_OBJECT "/"
41 #define LASH_IFACE_CONTROL DBUS_NAME_BASE ".Control"
43 struct lash_proxy_impl
45 void init();
47 void fetch_loaded_projects();
48 void fetch_project_clients(boost::shared_ptr<project> project_ptr);
50 static void error_msg(const std::string& msg);
51 static void info_msg(const std::string& msg);
53 static
54 DBusHandlerResult
55 dbus_message_hook(
56 DBusConnection * connection,
57 DBusMessage * message,
58 void * proxy);
60 bool
61 call(
62 bool response_expected,
63 const char* iface,
64 const char* method,
65 DBusMessage ** reply_ptr_ptr,
66 int in_type,
67 ...);
69 boost::shared_ptr<project>
70 on_project_added(
71 std::string name);
73 boost::shared_ptr<lash_client>
74 on_client_added(
75 boost::shared_ptr<project> project_ptr,
76 std::string id,
77 std::string name);
79 void exit();
81 bool _server_responding;
82 session * _session_ptr;
83 lash_proxy * _interface_ptr;
86 lash_proxy::lash_proxy(session * session_ptr)
88 _impl_ptr = new lash_proxy_impl;
89 _impl_ptr->_interface_ptr = this;
90 _impl_ptr->_session_ptr = session_ptr;
91 _impl_ptr->init();
94 lash_proxy::~lash_proxy()
96 delete _impl_ptr;
99 void
100 lash_proxy_impl::init()
102 _server_responding = false;
104 patchage_dbus_add_match("type='signal',interface='" DBUS_INTERFACE_DBUS "',member=NameOwnerChanged,arg0='" LASH_SERVICE "'");
105 patchage_dbus_add_match("type='signal',interface='" LASH_IFACE_CONTROL "',member=StudioAppeared");
106 patchage_dbus_add_match("type='signal',interface='" LASH_IFACE_CONTROL "',member=StudioDisappeared");
107 patchage_dbus_add_match("type='signal',interface='" LASH_IFACE_CONTROL "',member=ProjectAppeared");
108 patchage_dbus_add_match("type='signal',interface='" LASH_IFACE_CONTROL "',member=ProjectDisappeared");
109 patchage_dbus_add_match("type='signal',interface='" LASH_IFACE_CONTROL "',member=ProjectNameChanged");
110 patchage_dbus_add_match("type='signal',interface='" LASH_IFACE_CONTROL "',member=ProjectModifiedStatusChanged");
111 patchage_dbus_add_match("type='signal',interface='" LASH_IFACE_CONTROL "',member=ProjectDescriptionChanged");
112 patchage_dbus_add_match("type='signal',interface='" LASH_IFACE_CONTROL "',member=ProjectNotesChanged");
113 patchage_dbus_add_match("type='signal',interface='" LASH_IFACE_CONTROL "',member=ClientAppeared");
114 patchage_dbus_add_match("type='signal',interface='" LASH_IFACE_CONTROL "',member=ClientDisappeared");
115 patchage_dbus_add_match("type='signal',interface='" LASH_IFACE_CONTROL "',member=ClientNameChanged");
117 patchage_dbus_add_filter(dbus_message_hook, this);
119 // get initial list of projects
120 // calling any method to updates server responding status
121 // this also actiavtes lash object if it not activated already
122 //fetch_loaded_projects();
124 g_app->set_studio_availability(false);
127 bool
128 lash_proxy::is_active()
130 return _impl_ptr->_server_responding;
133 void
134 lash_proxy::try_activate()
136 std::list<lash_project_info> projects;
137 get_available_projects(projects);
140 void
141 lash_proxy::deactivate()
143 _impl_ptr->exit();
146 void
147 lash_proxy_impl::error_msg(const std::string& msg)
149 g_app->error_msg((std::string)"[LASH] " + msg);
152 void
153 lash_proxy_impl::info_msg(const std::string& msg)
155 g_app->info_msg((std::string)"[LASH] " + msg);
158 DBusHandlerResult
159 lash_proxy_impl::dbus_message_hook(
160 DBusConnection * connection,
161 DBusMessage * message,
162 void * proxy)
164 const char * project_name;
165 const char * new_project_name;
166 const char * object_name;
167 const char * old_owner;
168 const char * new_owner;
169 const char * value_string;
170 const char * client_id;
171 const char * client_name;
172 dbus_bool_t modified_status;
173 boost::shared_ptr<project> project_ptr;
174 boost::shared_ptr<lash_client> client_ptr;
176 assert(proxy);
177 lash_proxy_impl * me = reinterpret_cast<lash_proxy_impl *>(proxy);
179 //info_msg("dbus_message_hook() called.");
181 // Handle signals we have subscribed for in attach()
183 if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameOwnerChanged"))
185 if (!dbus_message_get_args(
186 message, &g_dbus_error,
187 DBUS_TYPE_STRING, &object_name,
188 DBUS_TYPE_STRING, &old_owner,
189 DBUS_TYPE_STRING, &new_owner,
190 DBUS_TYPE_INVALID))
192 error_msg(str(boost::format("dbus_message_get_args() failed to extract NameOwnerChanged signal arguments (%s)") % g_dbus_error.message));
193 dbus_error_free(&g_dbus_error);
194 return DBUS_HANDLER_RESULT_HANDLED;
197 if ((std::string)object_name != LASH_SERVICE)
199 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
202 if (old_owner[0] == '\0')
204 info_msg((std::string)"LASH activated.");
206 else if (new_owner[0] == '\0')
208 info_msg((std::string)"LASH deactivated.");
209 g_app->set_studio_availability(false);
210 me->_server_responding = false;
213 return DBUS_HANDLER_RESULT_HANDLED;
216 if (dbus_message_is_signal(message, LASH_IFACE_CONTROL, "StudioAppeared"))
218 info_msg((std::string)"Studio appeared.");
219 g_app->set_studio_availability(true);
221 return DBUS_HANDLER_RESULT_HANDLED;
224 if (dbus_message_is_signal(message, LASH_IFACE_CONTROL, "StudioDisappeared"))
226 info_msg((std::string)"Studio disappeared.");
227 g_app->set_studio_availability(false);
229 return DBUS_HANDLER_RESULT_HANDLED;
232 if (dbus_message_is_signal(message, LASH_IFACE_CONTROL, "ProjectAppeared"))
234 if (!dbus_message_get_args( message, &g_dbus_error,
235 DBUS_TYPE_STRING, &project_name,
236 DBUS_TYPE_INVALID))
238 error_msg(str(boost::format("dbus_message_get_args() failed to extract ProjectAppeared signal arguments (%s)") % g_dbus_error.message));
239 dbus_error_free(&g_dbus_error);
240 return DBUS_HANDLER_RESULT_HANDLED;
243 info_msg((std::string)"Project '" + project_name + "' appeared.");
244 me->on_project_added(project_name);
246 return DBUS_HANDLER_RESULT_HANDLED;
249 if (dbus_message_is_signal(message, LASH_IFACE_CONTROL, "ProjectDisappeared"))
251 if (!dbus_message_get_args(
252 message, &g_dbus_error,
253 DBUS_TYPE_STRING, &project_name,
254 DBUS_TYPE_INVALID))
256 error_msg(str(boost::format("dbus_message_get_args() failed to extract ProjectDisappeared signal arguments (%s)") % g_dbus_error.message));
257 dbus_error_free(&g_dbus_error);
258 return DBUS_HANDLER_RESULT_HANDLED;
261 info_msg((std::string)"Project '" + project_name + "' disappeared.");
262 me->_session_ptr->project_close(project_name);
264 return DBUS_HANDLER_RESULT_HANDLED;
268 if (dbus_message_is_signal(message, LASH_IFACE_CONTROL, "ProjectNameChanged"))
270 if (!dbus_message_get_args(
271 message, &g_dbus_error,
272 DBUS_TYPE_STRING, &project_name,
273 DBUS_TYPE_STRING, &new_project_name,
274 DBUS_TYPE_INVALID))
276 error_msg(str(boost::format("dbus_message_get_args() failed to extract ProjectNameChanged signal arguments (%s)") % g_dbus_error.message));
277 dbus_error_free(&g_dbus_error);
278 return DBUS_HANDLER_RESULT_HANDLED;
281 info_msg((std::string)"Project '" + project_name + "' renamed to '" + new_project_name + "'.");
283 project_ptr = me->_session_ptr->find_project_by_name(project_name);
284 if (project_ptr)
286 project_ptr->on_name_changed(new_project_name);
289 return DBUS_HANDLER_RESULT_HANDLED;
292 if (dbus_message_is_signal(message, LASH_IFACE_CONTROL, "ProjectModifiedStatusChanged"))
294 if (!dbus_message_get_args(
295 message, &g_dbus_error,
296 DBUS_TYPE_STRING, &project_name,
297 DBUS_TYPE_BOOLEAN, &modified_status,
298 DBUS_TYPE_INVALID))
300 error_msg(str(boost::format("dbus_message_get_args() failed to extract ProjectModifiedStatusChanged signal arguments (%s)") % g_dbus_error.message));
301 dbus_error_free(&g_dbus_error);
302 return DBUS_HANDLER_RESULT_HANDLED;
305 info_msg((std::string)"Project '" + project_name + "' modified status changed to '" + (modified_status ? "true" : "false") + "'.");
307 project_ptr = me->_session_ptr->find_project_by_name(project_name);
308 if (project_ptr)
310 project_ptr->on_modified_status_changed(modified_status);
313 return DBUS_HANDLER_RESULT_HANDLED;
316 if (dbus_message_is_signal(message, LASH_IFACE_CONTROL, "ProjectDescriptionChanged"))
318 if (!dbus_message_get_args(
319 message, &g_dbus_error,
320 DBUS_TYPE_STRING, &project_name,
321 DBUS_TYPE_STRING, &value_string,
322 DBUS_TYPE_INVALID))
324 error_msg(str(boost::format("dbus_message_get_args() failed to extract ProjectDescriptionChanged signal arguments (%s)") % g_dbus_error.message));
325 dbus_error_free(&g_dbus_error);
326 return DBUS_HANDLER_RESULT_HANDLED;
329 info_msg((std::string)"Project '" + project_name + "' description changed.");
331 project_ptr = me->_session_ptr->find_project_by_name(project_name);
332 if (project_ptr)
334 project_ptr->on_description_changed(value_string);
337 return DBUS_HANDLER_RESULT_HANDLED;
340 if (dbus_message_is_signal(message, LASH_IFACE_CONTROL, "ProjectNotesChanged"))
342 if (!dbus_message_get_args(
343 message, &g_dbus_error,
344 DBUS_TYPE_STRING, &project_name,
345 DBUS_TYPE_STRING, &value_string,
346 DBUS_TYPE_INVALID))
348 error_msg(str(boost::format("dbus_message_get_args() failed to extract ProjectNotesChanged signal arguments (%s)") % g_dbus_error.message));
349 dbus_error_free(&g_dbus_error);
350 return DBUS_HANDLER_RESULT_HANDLED;
353 info_msg((std::string)"Project '" + project_name + "' notes changed.");
355 project_ptr = me->_session_ptr->find_project_by_name(project_name);
356 if (project_ptr)
358 project_ptr->on_notes_changed(value_string);
361 return DBUS_HANDLER_RESULT_HANDLED;
364 if (dbus_message_is_signal(message, LASH_IFACE_CONTROL, "ClientAppeared"))
366 if (!dbus_message_get_args(
367 message, &g_dbus_error,
368 DBUS_TYPE_STRING, &client_id,
369 DBUS_TYPE_STRING, &project_name,
370 DBUS_TYPE_STRING, &client_name,
371 DBUS_TYPE_INVALID))
373 error_msg(str(boost::format("dbus_message_get_args() failed to extract ClientAppeared signal arguments (%s)") % g_dbus_error.message));
374 dbus_error_free(&g_dbus_error);
375 return DBUS_HANDLER_RESULT_HANDLED;
378 info_msg((std::string)"Client '" + client_id + "':'" + client_name + "' appeared in project '" + project_name + "'.");
380 project_ptr = me->_session_ptr->find_project_by_name(project_name);
381 if (project_ptr)
383 me->on_client_added(project_ptr, client_id, client_name);
386 return DBUS_HANDLER_RESULT_HANDLED;
389 if (dbus_message_is_signal(message, LASH_IFACE_CONTROL, "ClientDisappeared"))
391 if (!dbus_message_get_args(
392 message, &g_dbus_error,
393 DBUS_TYPE_STRING, &client_id,
394 DBUS_TYPE_STRING, &project_name,
395 DBUS_TYPE_INVALID))
397 error_msg(str(boost::format("dbus_message_get_args() failed to extract ClientDisappeared signal arguments (%s)") % g_dbus_error.message));
398 dbus_error_free(&g_dbus_error);
399 return DBUS_HANDLER_RESULT_HANDLED;
402 info_msg((std::string)"Client '" + client_id + "' of project '" + project_name + "' disappeared.");
404 client_ptr = me->_session_ptr->find_client_by_id(client_id);
405 if (client_ptr)
407 client_ptr->get_project()->on_client_removed(client_id);
408 me->_session_ptr->client_remove(client_id);
411 return DBUS_HANDLER_RESULT_HANDLED;
414 if (dbus_message_is_signal(message, LASH_IFACE_CONTROL, "ClientNameChanged"))
416 if (!dbus_message_get_args(
417 message, &g_dbus_error,
418 DBUS_TYPE_STRING, &client_id,
419 DBUS_TYPE_STRING, &client_name,
420 DBUS_TYPE_INVALID))
422 error_msg(str(boost::format("dbus_message_get_args() failed to extract ClientNameChanged signal arguments (%s)") % g_dbus_error.message));
423 dbus_error_free(&g_dbus_error);
424 return DBUS_HANDLER_RESULT_HANDLED;
427 info_msg((std::string)"Client '" + client_id + "' name changed to '" + client_name + "'.");
429 client_ptr = me->_session_ptr->find_client_by_id(client_id);
430 if (client_ptr)
432 client_ptr->on_name_changed(client_name);
435 return DBUS_HANDLER_RESULT_HANDLED;
438 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
441 bool
442 lash_proxy_impl::call(
443 bool response_expected,
444 const char* iface,
445 const char* method,
446 DBusMessage ** reply_ptr_ptr,
447 int in_type,
448 ...)
450 va_list ap;
452 va_start(ap, in_type);
454 _server_responding = patchage_dbus_call_valist(
455 response_expected,
456 LASH_SERVICE,
457 LASH_OBJECT,
458 iface,
459 method,
460 reply_ptr_ptr,
461 in_type,
462 ap);
464 va_end(ap);
466 return _server_responding;
469 void
470 lash_proxy_impl::fetch_loaded_projects()
472 DBusMessage* reply_ptr;
473 const char * reply_signature;
474 DBusMessageIter iter;
475 DBusMessageIter array_iter;
476 const char * project_name;
477 boost::shared_ptr<project> project_ptr;
479 if (!call(true, LASH_IFACE_CONTROL, "ProjectsGet", &reply_ptr, DBUS_TYPE_INVALID)) {
480 return;
483 reply_signature = dbus_message_get_signature(reply_ptr);
485 if (strcmp(reply_signature, "as") != 0)
487 error_msg((std::string)"ProjectsGet() reply signature mismatch. " + reply_signature);
488 goto unref;
491 dbus_message_iter_init(reply_ptr, &iter);
493 for (dbus_message_iter_recurse(&iter, &array_iter);
494 dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_INVALID;
495 dbus_message_iter_next(&array_iter))
497 dbus_message_iter_get_basic(&array_iter, &project_name);
498 project_ptr = on_project_added(project_name);
499 fetch_project_clients(project_ptr);
502 unref:
503 dbus_message_unref(reply_ptr);
506 void
507 lash_proxy_impl::fetch_project_clients(
508 boost::shared_ptr<project> project_ptr)
510 DBusMessage* reply_ptr;
511 const char * reply_signature;
512 DBusMessageIter iter;
513 DBusMessageIter array_iter;
514 DBusMessageIter struct_iter;
515 const char * client_id;
516 const char * client_name;
517 std::string project_name;
518 const char * project_name_cstr;
520 project_ptr->get_name(project_name);
521 project_name_cstr = project_name.c_str();
523 if (!call(
524 true,
525 LASH_IFACE_CONTROL,
526 "ProjectGetClients",
527 &reply_ptr,
528 DBUS_TYPE_STRING, &project_name_cstr,
529 DBUS_TYPE_INVALID))
531 return;
534 reply_signature = dbus_message_get_signature(reply_ptr);
536 if (strcmp(reply_signature, "a(ss)") != 0)
538 error_msg((std::string)"ProjectGetClients() reply signature mismatch. " + reply_signature);
539 goto unref;
542 dbus_message_iter_init(reply_ptr, &iter);
544 for (dbus_message_iter_recurse(&iter, &array_iter);
545 dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_INVALID;
546 dbus_message_iter_next(&array_iter))
548 dbus_message_iter_recurse(&array_iter, &struct_iter);
550 dbus_message_iter_get_basic(&struct_iter, &client_id);
551 dbus_message_iter_next(&struct_iter);
552 dbus_message_iter_get_basic(&struct_iter, &client_name);
553 dbus_message_iter_next(&struct_iter);
555 on_client_added(project_ptr, client_id, client_name);
558 unref:
559 dbus_message_unref(reply_ptr);
562 boost::shared_ptr<project>
563 lash_proxy_impl::on_project_added(
564 std::string name)
566 boost::shared_ptr<project> project_ptr(new project(_interface_ptr, name));
568 _session_ptr->project_add(project_ptr);
570 return project_ptr;
573 boost::shared_ptr<lash_client>
574 lash_proxy_impl::on_client_added(
575 boost::shared_ptr<project> project_ptr,
576 std::string id,
577 std::string name)
579 boost::shared_ptr<lash_client> client_ptr(
580 new lash_client(
581 _interface_ptr,
582 project_ptr.get(),
584 name));
586 project_ptr->on_client_added(client_ptr);
587 _session_ptr->client_add(client_ptr);
589 return client_ptr;
592 void
593 lash_proxy::get_available_projects(
594 std::list<lash_project_info>& projects)
596 DBusMessage * reply_ptr;
597 const char * reply_signature;
598 DBusMessageIter iter;
599 DBusMessageIter array_iter;
600 DBusMessageIter struct_iter;
601 DBusMessageIter dict_iter;
602 DBusMessageIter dict_entry_iter;
603 DBusMessageIter variant_iter;
604 const char * project_name;
605 const char * key;
606 const char * value_type;
607 dbus_uint32_t value_uint32;
608 const char * value_string;
609 lash_project_info project_info;
611 if (!_impl_ptr->call(true, LASH_IFACE_CONTROL, "ProjectsGetAvailable", &reply_ptr, DBUS_TYPE_INVALID))
613 return;
616 reply_signature = dbus_message_get_signature(reply_ptr);
618 if (strcmp(reply_signature, "a(sa{sv})") != 0)
620 lash_proxy_impl::error_msg((std::string)"ProjectsGetAvailable() reply signature mismatch. " + reply_signature);
621 goto unref;
624 dbus_message_iter_init(reply_ptr, &iter);
626 for (dbus_message_iter_recurse(&iter, &array_iter);
627 dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_INVALID;
628 dbus_message_iter_next(&array_iter))
630 dbus_message_iter_recurse(&array_iter, &struct_iter);
632 dbus_message_iter_get_basic(&struct_iter, &project_name);
634 project_info.name = project_name;
635 project_info.modification_time = 0;
636 project_info.description.erase();
638 dbus_message_iter_next(&struct_iter);
640 for (dbus_message_iter_recurse(&struct_iter, &dict_iter);
641 dbus_message_iter_get_arg_type(&dict_iter) != DBUS_TYPE_INVALID;
642 dbus_message_iter_next(&dict_iter))
644 dbus_message_iter_recurse(&dict_iter, &dict_entry_iter);
645 dbus_message_iter_get_basic(&dict_entry_iter, &key);
646 dbus_message_iter_next(&dict_entry_iter);
647 dbus_message_iter_recurse(&dict_entry_iter, &variant_iter);
648 value_type = dbus_message_iter_get_signature(&variant_iter);
649 if (value_type[0] != 0 && value_type[1] == 0)
651 switch (*value_type)
653 case DBUS_TYPE_UINT32:
654 if (strcmp(key, "Modification Time") == 0)
656 dbus_message_iter_get_basic(&variant_iter, &value_uint32);
657 project_info.modification_time = value_uint32;
659 break;
660 case DBUS_TYPE_STRING:
661 if (strcmp(key, "Description") == 0)
663 dbus_message_iter_get_basic(&variant_iter, &value_string);
664 project_info.description = value_string;
666 break;
671 projects.push_back(project_info);
674 unref:
675 dbus_message_unref(reply_ptr);
678 void
679 lash_proxy::load_project(
680 const std::string& project_name)
682 DBusMessage * reply_ptr;
683 const char * project_name_cstr;
685 project_name_cstr = project_name.c_str();
687 if (!_impl_ptr->call(true, LASH_IFACE_CONTROL, "ProjectOpen", &reply_ptr, DBUS_TYPE_STRING, &project_name_cstr, DBUS_TYPE_INVALID))
689 return;
692 dbus_message_unref(reply_ptr);
695 void
696 lash_proxy::save_all_projects()
698 DBusMessage * reply_ptr;
700 if (!_impl_ptr->call(true, LASH_IFACE_CONTROL, "ProjectsSaveAll", &reply_ptr, DBUS_TYPE_INVALID))
702 return;
705 dbus_message_unref(reply_ptr);
708 void
709 lash_proxy::save_project(
710 const std::string& project_name)
712 DBusMessage * reply_ptr;
713 const char * project_name_cstr;
715 project_name_cstr = project_name.c_str();
717 if (!_impl_ptr->call(true, LASH_IFACE_CONTROL, "ProjectSave", &reply_ptr, DBUS_TYPE_STRING, &project_name_cstr, DBUS_TYPE_INVALID))
719 return;
722 dbus_message_unref(reply_ptr);
725 void
726 lash_proxy::close_project(
727 const std::string& project_name)
729 DBusMessage * reply_ptr;
730 const char * project_name_cstr;
732 project_name_cstr = project_name.c_str();
734 if (!_impl_ptr->call(true, LASH_IFACE_CONTROL, "ProjectClose", &reply_ptr, DBUS_TYPE_STRING, &project_name_cstr, DBUS_TYPE_INVALID))
736 return;
739 dbus_message_unref(reply_ptr);
742 void
743 lash_proxy::close_all_projects()
745 DBusMessage * reply_ptr;
747 if (!_impl_ptr->call(true, LASH_IFACE_CONTROL, "ProjectsCloseAll", &reply_ptr, DBUS_TYPE_INVALID))
749 return;
752 dbus_message_unref(reply_ptr);
755 void
756 lash_proxy::project_rename(
757 const std::string& old_name,
758 const std::string& new_name)
760 DBusMessage * reply_ptr;
761 const char * old_name_cstr;
762 const char * new_name_cstr;
764 old_name_cstr = old_name.c_str();
765 new_name_cstr = new_name.c_str();
767 if (!_impl_ptr->call(
768 true,
769 LASH_IFACE_CONTROL,
770 "ProjectRename",
771 &reply_ptr,
772 DBUS_TYPE_STRING, &old_name_cstr,
773 DBUS_TYPE_STRING, &new_name_cstr,
774 DBUS_TYPE_INVALID))
776 return;
779 dbus_message_unref(reply_ptr);
782 void
783 lash_proxy::get_loaded_project_properties(
784 const std::string& name,
785 lash_loaded_project_properties& properties)
787 DBusMessage * reply_ptr;
788 const char * reply_signature;
789 DBusMessageIter iter;
790 DBusMessageIter dict_iter;
791 DBusMessageIter dict_entry_iter;
792 DBusMessageIter variant_iter;
793 const char * key;
794 const char * value_type;
795 dbus_bool_t value_bool;
796 const char * value_string;
797 const char * project_name_cstr;
799 project_name_cstr = name.c_str();
801 if (!_impl_ptr->call(
802 true,
803 LASH_IFACE_CONTROL,
804 "ProjectGetProperties",
805 &reply_ptr,
806 DBUS_TYPE_STRING, &project_name_cstr,
807 DBUS_TYPE_INVALID))
809 return;
812 reply_signature = dbus_message_get_signature(reply_ptr);
814 if (strcmp(reply_signature, "a{sv}") != 0)
816 lash_proxy_impl::error_msg((std::string)"ProjectGetProperties() reply signature mismatch. " + reply_signature);
817 goto unref;
820 dbus_message_iter_init(reply_ptr, &iter);
822 for (dbus_message_iter_recurse(&iter, &dict_iter);
823 dbus_message_iter_get_arg_type(&dict_iter) != DBUS_TYPE_INVALID;
824 dbus_message_iter_next(&dict_iter))
826 dbus_message_iter_recurse(&dict_iter, &dict_entry_iter);
827 dbus_message_iter_get_basic(&dict_entry_iter, &key);
828 dbus_message_iter_next(&dict_entry_iter);
829 dbus_message_iter_recurse(&dict_entry_iter, &variant_iter);
830 value_type = dbus_message_iter_get_signature(&variant_iter);
831 if (value_type[0] != 0 && value_type[1] == 0)
833 switch (*value_type)
835 case DBUS_TYPE_BOOLEAN:
836 if (strcmp(key, "Modified Status") == 0)
838 dbus_message_iter_get_basic(&variant_iter, &value_bool);
839 properties.modified_status = value_bool;
841 break;
842 case DBUS_TYPE_STRING:
843 if (strcmp(key, "Description") == 0)
845 dbus_message_iter_get_basic(&variant_iter, &value_string);
846 properties.description = value_string;
848 else if (strcmp(key, "Notes") == 0)
850 dbus_message_iter_get_basic(&variant_iter, &value_string);
851 properties.notes = value_string;
853 break;
858 unref:
859 dbus_message_unref(reply_ptr);
862 void
863 lash_proxy::project_set_description(
864 const std::string& project_name,
865 const std::string& description)
867 DBusMessage * reply_ptr;
868 const char * project_name_cstr;
869 const char * description_cstr;
871 project_name_cstr = project_name.c_str();
872 description_cstr = description.c_str();
874 if (!_impl_ptr->call(
875 true,
876 LASH_IFACE_CONTROL,
877 "ProjectSetDescription",
878 &reply_ptr,
879 DBUS_TYPE_STRING, &project_name_cstr,
880 DBUS_TYPE_STRING, &description_cstr,
881 DBUS_TYPE_INVALID))
883 return;
886 dbus_message_unref(reply_ptr);
889 void
890 lash_proxy::project_set_notes(
891 const std::string& project_name,
892 const std::string& notes)
894 DBusMessage * reply_ptr;
895 const char * project_name_cstr;
896 const char * notes_cstr;
898 project_name_cstr = project_name.c_str();
899 notes_cstr = notes.c_str();
901 if (!_impl_ptr->call(
902 true,
903 LASH_IFACE_CONTROL,
904 "ProjectSetNotes",
905 &reply_ptr,
906 DBUS_TYPE_STRING, &project_name_cstr,
907 DBUS_TYPE_STRING, &notes_cstr,
908 DBUS_TYPE_INVALID))
910 return;
913 dbus_message_unref(reply_ptr);
916 void
917 lash_proxy_impl::exit()
919 DBusMessage * reply_ptr;
921 if (!call(
922 true,
923 LASH_IFACE_CONTROL,
924 "Exit",
925 &reply_ptr,
926 DBUS_TYPE_INVALID))
928 return;
931 dbus_message_unref(reply_ptr);