diff --git a/src/zmapControl/remote/Makefile.am b/src/zmapControl/remote/Makefile.am new file mode 100755 index 0000000000000000000000000000000000000000..139597f9cb07c5d48bed18984ec4747f4b4f3438 --- /dev/null +++ b/src/zmapControl/remote/Makefile.am @@ -0,0 +1,2 @@ + + diff --git a/src/zmapControl/remote/Makefile.in b/src/zmapControl/remote/Makefile.in new file mode 100755 index 0000000000000000000000000000000000000000..4184c614ef6db6fa053f39279edc03f3f2ff3024 --- /dev/null +++ b/src/zmapControl/remote/Makefile.in @@ -0,0 +1,354 @@ +# Makefile.in generated by automake 1.9.5 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../.. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +subdir = zmapControl/remote +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/ac_doxygen.m4 \ + $(top_srcdir)/libcurl.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +SOURCES = +DIST_SOURCES = +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACECONN_CFLAGS = @ACECONN_CFLAGS@ +ACECONN_LIBS = @ACECONN_LIBS@ +ACLOCAL = @ACLOCAL@ +ALPHA_POPT = @ALPHA_POPT@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DOXYGEN_PAPER_SIZE = @DOXYGEN_PAPER_SIZE@ +DX_COND_chi_FALSE = @DX_COND_chi_FALSE@ +DX_COND_chi_TRUE = @DX_COND_chi_TRUE@ +DX_COND_chm_FALSE = @DX_COND_chm_FALSE@ +DX_COND_chm_TRUE = @DX_COND_chm_TRUE@ +DX_COND_doc_FALSE = @DX_COND_doc_FALSE@ +DX_COND_doc_TRUE = @DX_COND_doc_TRUE@ +DX_COND_dot_FALSE = @DX_COND_dot_FALSE@ +DX_COND_dot_TRUE = @DX_COND_dot_TRUE@ +DX_COND_html_FALSE = @DX_COND_html_FALSE@ +DX_COND_html_TRUE = @DX_COND_html_TRUE@ +DX_COND_latex_FALSE = @DX_COND_latex_FALSE@ +DX_COND_latex_TRUE = @DX_COND_latex_TRUE@ +DX_COND_man_FALSE = @DX_COND_man_FALSE@ +DX_COND_man_TRUE = @DX_COND_man_TRUE@ +DX_COND_pdf_FALSE = @DX_COND_pdf_FALSE@ +DX_COND_pdf_TRUE = @DX_COND_pdf_TRUE@ +DX_COND_ps_FALSE = @DX_COND_ps_FALSE@ +DX_COND_ps_TRUE = @DX_COND_ps_TRUE@ +DX_COND_rtf_FALSE = @DX_COND_rtf_FALSE@ +DX_COND_rtf_TRUE = @DX_COND_rtf_TRUE@ +DX_COND_xml_FALSE = @DX_COND_xml_FALSE@ +DX_COND_xml_TRUE = @DX_COND_xml_TRUE@ +DX_CONFIG = @DX_CONFIG@ +DX_DOCDIR = @DX_DOCDIR@ +DX_DOT = @DX_DOT@ +DX_DOXYGEN = @DX_DOXYGEN@ +DX_DVIPS = @DX_DVIPS@ +DX_EGREP = @DX_EGREP@ +DX_ENV = @DX_ENV@ +DX_FLAG_chi = @DX_FLAG_chi@ +DX_FLAG_chm = @DX_FLAG_chm@ +DX_FLAG_doc = @DX_FLAG_doc@ +DX_FLAG_dot = @DX_FLAG_dot@ +DX_FLAG_html = @DX_FLAG_html@ +DX_FLAG_man = @DX_FLAG_man@ +DX_FLAG_pdf = @DX_FLAG_pdf@ +DX_FLAG_ps = @DX_FLAG_ps@ +DX_FLAG_rtf = @DX_FLAG_rtf@ +DX_FLAG_xml = @DX_FLAG_xml@ +DX_HHC = @DX_HHC@ +DX_LATEX = @DX_LATEX@ +DX_MAKEINDEX = @DX_MAKEINDEX@ +DX_PDFLATEX = @DX_PDFLATEX@ +DX_PERL = @DX_PERL@ +DX_PROJECT = @DX_PROJECT@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FOOCANVAS_CFLAGS = @FOOCANVAS_CFLAGS@ +FOOCANVAS_LIBS = @FOOCANVAS_LIBS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBCURL = @LIBCURL@ +LIBCURL_CPPFLAGS = @LIBCURL_CPPFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +ZMAP_SRC_DIRS = @ZMAP_SRC_DIRS@ +_libcurl_config = @_libcurl_config@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +ac_pt_DX_DOT = @ac_pt_DX_DOT@ +ac_pt_DX_DOXYGEN = @ac_pt_DX_DOXYGEN@ +ac_pt_DX_DVIPS = @ac_pt_DX_DVIPS@ +ac_pt_DX_EGREP = @ac_pt_DX_EGREP@ +ac_pt_DX_HHC = @ac_pt_DX_HHC@ +ac_pt_DX_LATEX = @ac_pt_DX_LATEX@ +ac_pt_DX_MAKEINDEX = @ac_pt_DX_MAKEINDEX@ +ac_pt_DX_PDFLATEX = @ac_pt_DX_PDFLATEX@ +ac_pt_DX_PERL = @ac_pt_DX_PERL@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu zmapControl/remote/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu zmapControl/remote/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +uninstall-info-am: +tags: TAGS +TAGS: + +ctags: CTAGS +CTAGS: + + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-info-am + +.PHONY: all all-am check check-am clean clean-generic distclean \ + distclean-generic distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-exec \ + install-exec-am install-info install-info-am install-man \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-generic pdf pdf-am ps ps-am uninstall uninstall-am \ + uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/zmapControl/remote/zmapXRemote.c b/src/zmapControl/remote/zmapXRemote.c new file mode 100755 index 0000000000000000000000000000000000000000..f984fe6e6808f34cbbd745f2ad9cb62bbb55c405 --- /dev/null +++ b/src/zmapControl/remote/zmapXRemote.c @@ -0,0 +1,709 @@ +/* File: zmapXRemote.c + * Author: Roy Storey (rds@sanger.ac.uk) + * Copyright (c) Sanger Institute, 2005 + *------------------------------------------------------------------- + * ZMap 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * or see the on-line version at http://www.gnu.org/copyleft/gpl.txt + *------------------------------------------------------------------- + * This file is part of the ZMap genome database package + * originated by + * Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk, + * Roy Storey (Sanger Institute, UK) rds@sanger.ac.uk, + * Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk + * + * Description: + * + * Exported functions: See ZMap/zmapXRemote.h + * HISTORY: + * Last edited: Apr 14 12:01 2005 (rds) + * Created: Wed Apr 13 19:04:48 2005 (rds) + * CVS info: $Id: zmapXRemote.c,v 1.1 2005-04-14 12:08:52 rds Exp $ + *------------------------------------------------------------------- + */ + +#include "zmapXRemote_P.h" + +zMapXRemoteObj zMapXRemoteNew(void) +{ + zMapXRemoteObj object; + + /* Get current display, open it to check it's valid + and store in struct to save having to do it again */ + if (getenv("DISPLAY")) + { + char *display_str; + if((display_str = (char*)malloc (strlen(getenv("DISPLAY")) + 1)) == NULL) + return NULL; + + strcpy (display_str, getenv("DISPLAY")); + + zmapXDebug("Using DISPLAY: %s\n", display_str); + + object = g_new0(zMapXRemoteObjStruct,1); + if((object->display = XOpenDisplay (display_str)) == NULL) + { + zmapXDebug("Failed to open display '%s'\n", display_str); + + zmapXRemoteSetErrMsg(ZMAPXREMOTE_PRECOND, + "<message>Failed to open display '%s'</message>", + display_str); + free(display_str); + free(object); + return NULL; + } + object->init_called = FALSE; + object->is_server = FALSE; + } + + // XSynchronize(object->display, True); + + return object; +} + +void zMapXRemoteSetWindowID(zMapXRemoteObj object, Window id) +{ + object->window_id = id; + zmapXDebug("setting id to '0x%x' \n", (unsigned int) (object->window_id)); + return; +} + +void zMapXRemoteSetRequestAtomName(zMapXRemoteObj object, char *name) +{ + zmapXDebug("zMapXRemoteSetRequestAtomName change to '%s'\n", name); + object->request_atom = XInternAtom (object->display, name, False); + zmapXDebug("New name is %s\n", zmapXRemoteGetAtomName(object, object->request_atom)); + return ; +} + +void zMapXRemoteSetResponseAtomName(zMapXRemoteObj object, char *name) +{ + zmapXDebug("zMapXRemoteSetResponseAtomName change to '%s'\n", name); + object->response_atom = XInternAtom(object->display, name, False); + zmapXDebug("New name is %s\n", zmapXRemoteGetAtomName(object, object->response_atom)); + return ; +} + +int zMapXRemoteInitClient(zMapXRemoteObj object, Window id) +{ + + if(object->init_called == TRUE) + return 1; + + zMapXRemoteSetWindowID(object, id); + + if (! object->request_atom) + zMapXRemoteSetRequestAtomName(object, ZMAP_DEFAULT_REQUEST_ATOM_NAME); + + if (! object->response_atom) + zMapXRemoteSetResponseAtomName(object, ZMAP_DEFAULT_RESPONSE_ATOM_NAME); + + if (! object->version_sanity_atom) + object->version_sanity_atom = XInternAtom (object->display, ZMAP_XREMOTE_CURRENT_VERSION_ATOM, False); + + if (! object->app_sanity_atom) + object->app_sanity_atom = XInternAtom(object->display, ZMAP_XREMOTE_APPLICATION_ATOM, False); + + object->init_called = TRUE; + + return 1; +} + +int zMapXRemoteInitServer(zMapXRemoteObj object, Window id, char *appName, char *requestName, char *responseName) +{ + + if(object->init_called == TRUE) + return 1; + + zMapXRemoteSetWindowID(object, id); + + if (!object->request_atom && requestName) + zMapXRemoteSetRequestAtomName(object, requestName); + + if (!object->response_atom && responseName) + zMapXRemoteSetResponseAtomName(object, responseName); + + if (! object->version_sanity_atom) + { + object->version_sanity_atom = XInternAtom (object->display, ZMAP_XREMOTE_CURRENT_VERSION_ATOM, False); + zmapXRemoteChangeProperty(object, object->version_sanity_atom, ZMAP_XREMOTE_CURRENT_VERSION); + } + if (! object->app_sanity_atom) + { + object->app_sanity_atom = XInternAtom(object->display, ZMAP_XREMOTE_APPLICATION_ATOM, False); + zmapXRemoteChangeProperty(object, object->app_sanity_atom, appName); + } + + object->is_server = TRUE; + object->init_called = TRUE; + + return 1; +} + +int zMapXRemoteSendRemoteCommands(zMapXRemoteObj object){ + int response_status = 0; + + zmapXDebug("\n trying %s \n", "a broken function..."); + + return response_status; +} + +/*=======================================================================*/ +/* zMapXRemoteSendRemoteCommand is based on the original file 'remote.c' + * which carried this notice : */ +/* -*- Mode:C; tab-width: 8 -*- + * remote.c --- remote control of Netscape Navigator for Unix. + * version 1.1.3, for Netscape Navigator 1.1 and newer. + * + * Copyright (c) 1996 Netscape Communications Corporation, all rights reserved. + * Created: Jamie Zawinski <jwz@netscape.com>, 24-Dec-94. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation. No representations are made about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + ************* + * NOTE: + * the file has been modified, to use a different protocol from the one + * described in http://home.netscape.com/newsref/std/x-remote.html + ************* + */ +int zMapXRemoteSendRemoteCommand(zMapXRemoteObj object, char *command) +{ + int result = 0; + Bool isDone = False; + XEvent event; + Display *dpy = object->display; + Window window = object->window_id; + unsigned long event_mask = (PropertyChangeMask | StructureNotifyMask); + + if(object->is_server == TRUE) + return result; + + result = zmapXRemoteCheckWindow(object); + + if(result != 0) + return 9; + + zmapXDebug("remote: (writing %s '%s' to 0x%x)\n", + zmapXRemoteGetAtomName(object, object->request_atom), + command, (unsigned int) object->window_id); + + result = zmapXRemoteChangeProperty(object, object->request_atom, command); + + XSelectInput(object->display, object->window_id, event_mask); + + zmapXDebug("sent '%s'...\n", command); + + while (!isDone && !windowError) + { + zmapXDebug("%s"," - while: I'm still waiting...\n"); + + // if(XPending(dpy)) + XNextEvent (object->display, &event); + + zmapXDebug(" - while: got event type %d\n", event.type); + + if (windowError){ + result = 6; + goto DONE; + } + + if (event.xany.type == DestroyNotify && + event.xdestroywindow.window == window) + { + zmapXRemoteSetErrMsg(ZMAPXREMOTE_UNAVAILABLE, + "<display>%s</display>" + "<windowid>0x%0x</windowid>" + "<message>window was destroyed</message>", + XDisplayString(dpy), window); + zmapXDebug("remote : window 0x%x was destroyed.\n", + (unsigned int) object->window_id); + result = 6; /* invalid window */ + goto DONE; + } + else if (event.xany.type == PropertyNotify && + event.xproperty.state == PropertyNewValue && + event.xproperty.window == object->window_id && + event.xproperty.atom == object->response_atom) + { + Atom actual_type; + int actual_format; + unsigned long nitems, bytes_after; + unsigned char *commandResult; + int x_status; + + zmapXTrapErrors(); + x_status = XGetWindowProperty(object->display, object->window_id, + object->response_atom, /* XA_XREMOTE_RESPONSE, */ + 0, (65536 / sizeof (long)), + /* True or False ?????????? wed 13 change, was true */ + False, /* atomic delete after */ + XA_STRING, + &actual_type, &actual_format, + &nitems, &bytes_after, + &commandResult); + zmapXUntrapErrors(); + + if (!windowError && x_status == Success && commandResult && *commandResult) + { + zmapXDebug("remote: (server sent %s '%s' to 0x%x.)\n", + zmapXRemoteGetAtomName(object, object->response_atom), + commandResult, + (unsigned int) object->window_id); + + } + + if (x_status != Success) + { + zmapXRemoteSetErrMsg(ZMAPXREMOTE_UNAVAILABLE, + "<display>%s</display>" + "<windowid>0x%0x</windowid>" + "<message>failed reading atom '%s' from window</message>", + XDisplayString(dpy), window, + zmapXRemoteGetAtomName(object, object->response_atom)); + zmapXDebug("remote: failed reading %s from window 0x%0x.\n", + zmapXRemoteGetAtomName(object, object->response_atom), + (unsigned int) object->window_id); + result = 6; /* invalid window */ + isDone = True; + } + else + { + if (commandResult && *commandResult) + { + zmapXDebug("cmd result| %s\n", commandResult); + result = 0; /* everything OK */ + isDone = True; + } + else + { + zmapXRemoteSetErrMsg(ZMAPXREMOTE_CONFLICT, + "<display>%s</display>" + "<windowid>0x%0x</windowid>" + "<message>invalid data on atom '%s'</message>", + XDisplayString(dpy), window, + zmapXRemoteGetAtomName(object, object->response_atom)); + zmapXDebug("remote: invalid data on %s property of window 0x%0x.\n", + zmapXRemoteGetAtomName(object, object->response_atom), + (unsigned int) object->window_id); + result = 6; /* invalid window */ + isDone = True; + } + } + + if (commandResult) + XFree (commandResult); + } + else if (event.xany.type == PropertyNotify && + event.xproperty.window == (object->window_id) && + event.xproperty.state == PropertyDelete && + event.xproperty.atom == (object->request_atom)) + { + zmapXDebug("remote: (server 0x%0x has accepted %s)\n", + (unsigned int) object->window_id, + zmapXRemoteGetAtomName(object, object->request_atom) + ); + } + else + { + zmapXDebug("%s\n"," - else: still waiting"); + } + } + + DONE: + zmapXDebug("%s\n"," - DONE: done"); + + return result; +} + +char *zMapXRemoteGetResponse(zMapXRemoteObj object) +{ + zmapXDebug("%s\n", "just a message to say we're in zMapXRemoteGetResponse"); + + if(windowError) + { + return zmapXRemoteGetErrorAsResponse(); + } + else + { + zmapXDebug("%s\n", "else"); + return zmapXRemoteGetComputedContent(object, object->response_atom, True); + } +} + +GdkAtom zMapXRemoteGdkRequestAtom(zMapXRemoteObj object){ + GdkAtom req; + zmapXDebug("%s\n", "just a message to say we're in zMapXRemoteGdkRequestAtom"); + req = gdk_x11_xatom_to_atom(object->request_atom); + return req; +} + +GdkAtom zMapXRemoteGdkResponseAtom(zMapXRemoteObj object){ + GdkAtom res; + zmapXDebug("%s\n", "just a message to say we're in zMapXRemoteGdkResponseAtom"); + res = gdk_x11_xatom_to_atom(object->response_atom); + return res; +} + +char *zMapXRemoteGetRequest(zMapXRemoteObj object) +{ + zmapXDebug("%s\n", "just a message to say we're in zMapXRemoteGetRequest"); + return zmapXRemoteGetComputedContent(object, object->request_atom, True); +} + +int zMapXRemoteSetReply(zMapXRemoteObj object, char *content) +{ + int result = 0; + + if(object->is_server == FALSE) + return result; + zmapXDebug("%s\n", "just a message to say we're in zMapXRemoteSetReply"); + result = zmapXRemoteChangeProperty(object, object->response_atom, content); + return result; +} + + + + +/* ====================================================== */ +/* INTERNALS */ +/* ====================================================== */ + +char *zmapXRemoteGetAtomName(zMapXRemoteObj obj, Atom atom) +{ + char *name; + name = g_strdup(XGetAtomName(obj->display, atom)); + return name; +} + +int zmapXRemoteChangeProperty(zMapXRemoteObj object, Atom atom, char *change_to) +{ + Window win; + + win = object->window_id; + + zmapXTrapErrors(); + zmapXRemoteErrorStatus = ZMAPXREMOTE_PRECOND; + + zmapXDebug("Changing atom '%s' to value '%s'\n", zmapXRemoteGetAtomName(object, atom), change_to); + XChangeProperty (object->display, win, + atom, XA_STRING, 8, + PropModeReplace, (unsigned char *)change_to, + strlen (change_to) + ); + XSync(object->display, False); + if(windowError) + return 2; + zmapXUntrapErrors(); + + return 0; +} + +/* Check the client and server were compiled using the same <ZMap/zmapXRemote.h> */ + +int zmapXRemoteCheckWindow (zMapXRemoteObj object) +{ + int r = 1; /* failure */ + r = zmapXRemoteCmpAtomString(object, object->version_sanity_atom, ZMAP_XREMOTE_CURRENT_VERSION); + if(object->remote_app) + r += zmapXRemoteCmpAtomString(object, object->app_sanity_atom, object->remote_app); + return r; +} + +int zmapXRemoteCmpAtomString (zMapXRemoteObj object, Atom atom, char *expected) +{ + Atom type; + int format, x_status; + unsigned long nitems, bytesafter; + unsigned char *versionStr = 0; + Window win; + + win = object->window_id; + + zmapXTrapErrors(); + zmapXRemoteErrorStatus = ZMAPXREMOTE_PRECOND; + x_status = XGetWindowProperty (object->display, win, + atom, + 0, (65536 / sizeof (long)), + False, XA_STRING, + &type, &format, &nitems, &bytesafter, + &versionStr); + zmapXUntrapErrors(); + + if(windowError) + return 4; /* failure */ + + if (x_status != Success || !versionStr) + { + zmapXRemoteSetErrMsg(ZMAPXREMOTE_PRECOND, + "Warning : window 0x%x is not a valid remote-controllable window.", + (unsigned int) win + ); + zmapXDebug("Warning : window 0x%x is not a valid remote-controllable window.\n", + (unsigned int) win + ); + return 2; /* failure */ + } + + if (strcmp ((char*)versionStr, expected) != 0) + { + zmapXRemoteSetErrMsg(ZMAPXREMOTE_PRECOND, + "Warning : remote controllable window 0x%x uses " + "different version %s of remote control system, expected " + + "version %s.", + (unsigned int) win, + versionStr, expected); + zmapXDebug("Warning : remote controllable window 0x%x uses " + "different version %s of remote control system, expected " + "version %s.\n", + (unsigned int) win, + versionStr, expected); + } + + XFree (versionStr); + + return 0; /* success */ +} + +char *zmapXRemoteGetComputedContent(zMapXRemoteObj object, Atom atom, Bool atomic_delete) +{ + Atom type; + int format; + unsigned long nitems, bytesafter; + unsigned char *computedString = 0; + int x_status; + Window win; + char *atom_content; + + win = object->window_id; + + zmapXTrapErrors(); + zmapXRemoteErrorStatus = ZMAPXREMOTE_INTERNAL; + + x_status = XGetWindowProperty (object->display, win, + atom, + 0, (65536 / sizeof (long)), + atomic_delete, XA_STRING, + &type, &format, &nitems, &bytesafter, + &computedString); + zmapXUntrapErrors(); + if(windowError || x_status != Success) + { + zmapXRemoteSetErrMsg(ZMAPXREMOTE_INTERNAL, + "couldn't get the content from the atom with name %s", + zmapXRemoteGetAtomName(object, atom) + ); + return zmapXRemoteGetErrorAsResponse(); + } + //////////////////#ifdef EEEEEEEEEEEEEEEEE + else if(type != XA_STRING) + { + zmapXRemoteSetErrMsg(ZMAPXREMOTE_INTERNAL, + "couldn't get the atom with name %s and type STRING, got type 0x%0x", + zmapXRemoteGetAtomName(object, atom), type + ); + return zmapXRemoteGetErrorAsResponse(); + } + ////////////#endif + else + { + if(computedString && *computedString) + { + zmapXDebug("atom %s, value %s, \n", zmapXRemoteGetAtomName(object, atom), computedString); + atom_content = g_strdup((char *)computedString); + return atom_content; + } + else + { + zmapXDebug("%s\n", "empty atom"); + return ""; + } + } + if(computedString) + XFree(computedString); + + return ""; +} + +/*============ ERROR FUNCTIONS BELOW =================== */ + +#define xml_simple_start "<simplemessage>" +#define xml_simple_end "</simplemessage>" + +/* =============================================================== */ +char *zmapXRemoteGetErrorAsResponse(void) /* Translation for users */ +/* =============================================================== */ +{ + char *err; + + if(zmapXRemoteErrorText == NULL) + { + zMapXRemoteSimpleErrMsgStruct errorTable[] = + { + /* 1xx Informational */ + /* 2xx Successful */ + {ZMAPXREMOTE_METAERROR , xml_simple_start "meta error" xml_simple_end}, + {ZMAPXREMOTE_NOCONTENT , xml_simple_start "no content was returned" xml_simple_end}, + /* 3xx Redirection */ + /* Redirect??? I don't think so */ + /* 4xx Client Errors */ + {ZMAPXREMOTE_BADREQUEST , xml_simple_start "you made a bad request to the server" xml_simple_end}, + {ZMAPXREMOTE_FORBIDDEN , xml_simple_start "you are not allowed to see this" xml_simple_end}, + {ZMAPXREMOTE_UNKNOWNCMD , xml_simple_start "unknown command" xml_simple_end}, + {ZMAPXREMOTE_PRECOND , xml_simple_start "something went wrong with sanity checking" xml_simple_end}, + /* 5xx Server Errors */ + {ZMAPXREMOTE_INTERNAL , xml_simple_start "Internal Server Error" xml_simple_end}, + {ZMAPXREMOTE_UNKNOWNATOM , xml_simple_start "Unknown Server Atom" xml_simple_end}, + {ZMAPXREMOTE_NOCREATE , xml_simple_start "No Resource was created" xml_simple_end}, + {ZMAPXREMOTE_UNAVAILABLE , xml_simple_start "Unavailable Server Resource" xml_simple_end}, + {ZMAPXREMOTE_TIMEDOUT , xml_simple_start "Server Timeout" xml_simple_end}, + /* NULL to end the while loop below! */ + {ZMAPXREMOTE_OK , NULL} + } ; + zMapXRemoteSimpleErrMsg curr_err; + + curr_err = &errorTable[0]; + while (curr_err->message != NULL) + { + if(curr_err->status == zmapXRemoteErrorStatus) + { + zmapXRemoteSetErrMsg(curr_err->status, curr_err->message); + break; + } + else + curr_err++; + } + } + + err = g_strdup_printf(ZMAP_XREMOTE_REPLY_FORMAT, + zmapXRemoteErrorStatus, + zmapXRemoteErrorText); + return err; +} +#undef xml_simple_start +#undef xml_simple_end + + +void zmapXRemoteSetErrMsg(zMapXRemoteStatus status, char *msg, ...) +{ + va_list args; + char *callErr; + + if(zmapXRemoteErrorText != NULL) + g_free(zmapXRemoteErrorText); + + /* Format the supplied error message. */ + va_start(args, msg) ; + callErr = g_strdup_vprintf(msg, args) ; + va_end(args) ; + + + zmapXRemoteErrorStatus = status; + zmapXRemoteErrorText = g_strdup_printf(ZMAP_XREMOTE_ERROR_XML_FORMAT, + callErr) ; + + g_free(callErr); + + return; +} + + +int zmapXErrorHandler(Display *dpy, XErrorEvent *e ) +{ + char errorText[1024]; + + windowError = True; + + XGetErrorText( dpy, e->error_code, errorText, sizeof(errorText) ); + /* N.B. The continuation of string here */ + zmapXRemoteSetErrMsg(zmapXRemoteErrorStatus, + "<display>%s</display>" + "<windowid>0x%0x</windowid>" + "<message>%s</message>", + XDisplayString(dpy), e->resourceid, errorText); + + zmapXDebug("%s\n","**********************************"); + zmapXDebug("X Error: %s\n", errorText); + zmapXDebug("%s\n","**********************************"); + + return 1; /* This is ignored by the server */ +} + +void zmapXTrapErrors(void) +{ + windowError = False; + XSetErrorHandler(zmapXErrorHandler); + return ; +} +void zmapXUntrapErrors(void) +{ + XSetErrorHandler(NULL); + if(!windowError) + zmapXRemoteErrorStatus = ZMAPXREMOTE_INTERNAL; + return ; +} + +/* ======================================================= */ +/* END */ +/* ======================================================= */ + + + +#ifdef AN_ALTERNATE_ZMAPXREMOTEGETCOMPUTEDCONTENT +static Bool +zmapXRemoteGetComputedContent (zMapXRemoteObj object, Atom atom, char *content) +{ + Atom type; + int format; + unsigned long nitems, bytesafter; + unsigned char *computedString = 0; + int x_status; + char *computedString; + int result; + + *content = 0; + + zmapXTrapErrors(); + zmapXRemoteErrorStatus = ZMAPXREMOTE_INTERNAL; + result = XGetWindowProperty (object->display, + object->window_id, + atom, + 0, (65536 / sizeof (long)), + False, XA_STRING, + &type, &format, &nitems, + &bytes_after, &computedString); + zmapXUntrapErrors(); + if (windowError || result != Success) + return False; + + if (type != XA_STRING) + { + XFree (computedString); + return False; + } + + *content = *computedString; + + XFree (computedString); + + return True; +} +#endif + diff --git a/src/zmapControl/remote/zmapXRemote_P.h b/src/zmapControl/remote/zmapXRemote_P.h new file mode 100755 index 0000000000000000000000000000000000000000..efa6065aa34690793c30f1cf9085f33c75cfce94 --- /dev/null +++ b/src/zmapControl/remote/zmapXRemote_P.h @@ -0,0 +1,150 @@ +/* File: zmapXRemote_P.h + * Author: Roy Storey (rds@sanger.ac.uk) + * Copyright (c) Sanger Institute, 2005 + *------------------------------------------------------------------- + * ZMap 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * or see the on-line version at http://www.gnu.org/copyleft/gpl.txt + *------------------------------------------------------------------- + * This file is part of the ZMap genome database package + * originated by + * Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk, + * Roy Storey (Sanger Institute, UK) rds@sanger.ac.uk, + * Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk + * + * Description: + * + * Exported functions: None + * HISTORY: + * Last edited: Apr 14 13:08 2005 (rds) + * Created: Thu Apr 14 13:07:51 2005 (rds) + * CVS info: $Id: zmapXRemote_P.h,v 1.1 2005-04-14 12:08:52 rds Exp $ + *------------------------------------------------------------------- + */ + +#ifndef ZMAPXREMOTE_P_H +#define ZMAPXREMOTE_P_H + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +#include <ZMap/zmapXRemote.h> /* Public header */ + + +typedef struct _zMapXRemoteObjStruct +{ + Display *display; /* The display XOpenDisplay() succeeded in creating this */ + Window window_id; /* The window id of either ourselves (server) or + foreign window (client)*/ + + Atom version_sanity_atom; /* The atom to check version sanity */ + Atom app_sanity_atom; /* The atom to check application sanity */ + Atom request_atom; /* The request atom */ + Atom response_atom; /* The response atom */ + + char *remote_app; + + gboolean init_called; /* Just keeps track of initialisation, shouldn't really be needed */ + gboolean is_server; /* TRUE if we're a server */ + +} zMapXRemoteObjStruct ; + +/*========= For Error Stuff below =========== */ +typedef struct +{ + zMapXRemoteStatus status ; + char *message ; +} zMapXRemoteSimpleErrMsgStruct, *zMapXRemoteSimpleErrMsg ; + + +/*========= Some Private functions ===========*/ +char *zmapXRemoteGetComputedContent(zMapXRemoteObj object, Atom atom, Bool atomic_delete); +char *zmapXRemoteGetAtomName(zMapXRemoteObj obj, Atom atom); + +int zmapXRemoteCheckWindow (zMapXRemoteObj object); +int zmapXRemoteCmpAtomString (zMapXRemoteObj object, Atom atom, char *expected); +int zmapXRemoteChangeProperty(zMapXRemoteObj object, Atom atom, char *change_to); + + +/*====================== DEBUGGING =========================*/ +//////////////////////////////////////////#define DO_DEBUGGING +#ifdef DO_DEBUGGING +#define ZMAP_MSG_FORMAT_STRING "(%s, line %d) - " +#define zmapXDebug(FORMAT, ...) \ +G_STMT_START{ \ + g_printerr(ZMAP_MSG_FORMAT_STRING FORMAT, \ + __FILE__, \ + __LINE__, \ + __VA_ARGS__) ; \ +}G_STMT_END +#else +#define zmapXDebug(FORMAT, ...) +#endif +/*==========================================================*/ + + +/*==================================================================*/ +/* Xlib error trapping stuff. Needed to stop bombing by X on errors */ +static Bool windowError = False; + +void zmapXTrapErrors(void); +void zmapXUntrapErrors(void); +int zmapXErrorHandler(Display *dpy, XErrorEvent *e); + +/* This is quite nauseating... + * + * 1. you need to set zmapXRemoteErrorStatus after zmapXTrapErrors and + * before call that might fail. + * + * 2. zmapXErrorHandler passes zmapXRemoteErrorStatus to + * zmapXRemoteSetErrMsg which just sets it to the same thing again. + * + * 3. behaviour of zmapXUntrapErrors() depends on value of windowError. + * + * 4. So typical usage is: + * zmapXTrapErrors(); + * zmapXRemoteErrorStatus = ZMAPXREMOTE_(error context code bit) unless ZMAPXREMOTE_INTERNAL is appropriate + * XLibraryCall(...); + * zmapXUntrapErrors(); + * if(windowError) + * return zmapXRemoteErrorStatus; + + * However, this is preferable to using gdk calls for a couple of reasons. + * 1. we get our own error strings. + * 2. we get the error string from XErrorEvent rather than just an error code + * Typical gdk version is basically the same + * gdk_error_trap_push (); + * XLibraryCall(...); + * gdk_flush (); + + * if (code = gdk_error_trap_pop ()) + * { + * // we'd end up calling this every time, rather than the above, which I + * // consider to be a bit better encapsulated. + * char errorText[1024]; + * XGetErrorText(gdk_x11_get_default_xdisplay(), code, errorText, sizeof(errorText)); + * } + * + * + */ +static zMapXRemoteStatus zmapXRemoteErrorStatus = ZMAPXREMOTE_INTERNAL; +static char *zmapXRemoteErrorText = NULL; +void zmapXRemoteSetErrMsg(zMapXRemoteStatus status, char *msg, ...); +char *zmapXRemoteGetErrorAsResponse(void); +/* End of Xlib Error stuff */ +/*==========================================================*/ + +#endif /* ZMAPXREMOTE_P_H */