$search
00001 00002 /*************************************************************************** 00003 * xpdfctrl.cpp - ROS slide presenter 00004 * 00005 * Created: Fri Sep 3 11:14:26 2010 00006 * Copyright 2010 Tim Niemueller [www.niemueller.de] 00007 * 2010 Carnegie Mellon University 00008 * 2010 Intel Labs Pittsburgh, Intel Research 00009 * 00010 ****************************************************************************/ 00011 00012 /* This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation; either version 2 of the License, or 00015 * (at your option) any later version. 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU Library General Public License for more details. 00021 * 00022 * Read the full text in the LICENSE.GPL file in the doc directory. 00023 */ 00024 00025 #include "xpdfctrl.h" 00026 00027 #include <cstring> 00028 #include <cstdio> 00029 #include <cstdlib> 00030 #include <cstdarg> 00031 #include <stdexcept> 00032 00043 XpdfControl::XpdfControl(const char *remote) 00044 { 00045 __hidden = true; 00046 __remote = strdup(remote); 00047 } 00048 00050 XpdfControl::~XpdfControl() 00051 { 00052 free(__remote); 00053 } 00054 00056 void 00057 XpdfControl::next_page() 00058 { 00059 execute_command("nextPage"); 00060 } 00061 00063 void 00064 XpdfControl::prev_page() 00065 { 00066 execute_command("prevPage"); 00067 } 00068 00072 void 00073 XpdfControl::goto_page(unsigned int page) 00074 { 00075 execute_command("'gotoPage(%u)'", page); 00076 } 00077 00079 void 00080 XpdfControl::hide() 00081 { 00082 execute_command("quit"); 00083 } 00084 00090 void 00091 XpdfControl::load_file(const char *filename) 00092 { 00093 execute_command("'' -fullscreen '%s'", filename); 00094 } 00095 00101 void 00102 XpdfControl::execute_command(const char *format, ...) 00103 { 00104 va_list arg; 00105 va_start(arg, format); 00106 char *cmd; 00107 if (vasprintf(&cmd, format, arg) != -1) { 00108 std::string cmds = cmd; free(cmd); 00109 char *cmdline; 00110 if (asprintf(&cmdline, "xpdf -remote '%s' -exec %s &", __remote, cmds.c_str()) != -1) { 00111 std::string cmdlines = cmdline; free(cmdline); 00112 if (system(cmdlines.c_str()) != 0) { 00113 std::runtime_error e(std::string("Executing ") + cmdlines + "failed"); 00114 throw e; 00115 } 00116 } else { 00117 throw std::runtime_error("Allocating memory for command string failed"); 00118 } 00119 } else { 00120 throw std::runtime_error("Allocating memory for Xpdf command string failed"); 00121 } 00122 va_end(arg); 00123 }