00001 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00033 
00034 #ifndef GROOVX_VISX_TCLPKG_RH_CC_UTC20050628171008_DEFINED
00035 #define GROOVX_VISX_TCLPKG_RH_CC_UTC20050628171008_DEFINED
00036 
00037 #include "visx/tclpkg-rh.h"
00038 
00039 #include "visx/tclpkg-rh.h"
00040 
00041 #include "nub/objfactory.h"
00042 
00043 #include "tcl/objpkg.h"
00044 #include "tcl/pkg.h"
00045 #include "tcl/tracertcl.h"
00046 
00047 #include "rutz/error.h"
00048 #include "rutz/fstring.h"
00049 #include "rutz/shared_ptr.h"
00050 #include "rutz/serialport.h"
00051 
00052 #include "visx/eventresponsehdlr.h"
00053 #include "visx/responsehandler.h"
00054 #include "visx/kbdresponsehdlr.h"
00055 #include "visx/nullresponsehdlr.h"
00056 
00057 #include <tk.h>
00058 
00059 #include "rutz/trace.h"
00060 #include "rutz/debug.h"
00061 GVX_DBG_REGISTER
00062 
00064 
00065 
00066 
00068 
00069 namespace
00070 {
00071   class SerialEventSource
00072   {
00073   public:
00074     SerialEventSource(Tcl_Interp* interp, const char* serial_device) :
00075       itsInterp(interp),
00076       itsPort(serial_device)
00077     {
00078       Tcl_CreateEventSource(setupProc, checkProc, static_cast<void*>(this));
00079     }
00080 
00081     ~SerialEventSource()
00082     {
00083       Tcl_DeleteEventSource(setupProc, checkProc, static_cast<void*>(this));
00084     }
00085 
00086   private:
00087     Tcl_Interp* itsInterp;
00088     rutz::serial_port itsPort;
00089 
00090     static void setupProc(ClientData , int flags)
00091     {
00092       if ( !(flags & TCL_FILE_EVENTS) ) return;
00093 
00094       Tcl_Time block_time;
00095       block_time.sec = 0;
00096       block_time.usec = 1000;
00097 
00098       Tcl_SetMaxBlockTime(&block_time);
00099     }
00100 
00101     static void checkProc(ClientData clientData, int flags)
00102     {
00103       if ( !(flags & TCL_FILE_EVENTS) ) return;
00104 
00105       SerialEventSource* source = static_cast<SerialEventSource*>(clientData);
00106 
00107       if ( !source->itsPort.is_closed() )
00108         {
00109           int n;
00110           while ( (n = source->itsPort.get()) != EOF)
00111             {
00112               if ( n >= 'A' && n <= 'H' )
00113                 {
00114                   dbg_eval_nl(3, (n-'A'));
00115 
00116                   Tk_FakeWin* tkwin = reinterpret_cast<Tk_FakeWin*>(
00117                                          Tk_MainWindow(source->itsInterp));
00118                   Display* display = Tk_Display(tkwin);
00119 
00120                   char keystring[2] = { char(n), '\0' };
00121                   KeySym keysym = XStringToKeysym(keystring);
00122                   KeyCode keycode = XKeysymToKeycode(display, keysym);
00123 
00124                   XEvent ev;
00125                   ev.xkey.type = KeyPress;
00126                   ev.xkey.send_event = True;
00127                   ev.xkey.display = display;
00128                   ev.xkey.window = Tk_WindowId(tkwin);
00129                   ev.xkey.keycode = keycode;
00130                   ev.xkey.state = 0;
00131                   Tk_QueueWindowEvent(&ev, TCL_QUEUE_TAIL);
00132                 }
00133             }
00134         }
00135     }
00136 
00137   private:
00138     SerialEventSource(const SerialEventSource&);
00139     SerialEventSource& operator=(const SerialEventSource&);
00140   };
00141 
00142   rutz::shared_ptr<SerialEventSource> theEventSource;
00143 
00144   void startSerial(Tcl_Interp* interp, const char* device)
00145   {
00146     theEventSource.reset(new SerialEventSource(interp, device));
00147   }
00148 }
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 extern "C"
00158 int Responsehandler_Init(Tcl_Interp* interp)
00159 {
00160 GVX_TRACE("Responsehandler_Init");
00161 
00162   GVX_PKG_CREATE(pkg, interp, "ResponseHandler", "4.$Revision: 10065 $");
00163   pkg->inherit_pkg("io");
00164   tcl::def_basic_type_cmds<ResponseHandler>(pkg, SRC_POS);
00165   pkg->namesp_alias("Rh");
00166 
00167   GVX_PKG_RETURN(pkg);
00168 }
00169 
00170 extern "C"
00171 int Eventresponsehdlr_Init(Tcl_Interp* interp)
00172 {
00173 GVX_TRACE("Eventresponsehdlr_Init");
00174 
00175   GVX_PKG_CREATE(pkg, interp, "EventResponseHdlr", "4.$Revision: 10065 $");
00176   tcl::def_creator<EventResponseHdlr>(pkg);
00177   pkg->inherit_pkg("ResponseHandler");
00178   tcl::def_tracing(pkg, EventResponseHdlr::tracer);
00179 
00180   tcl::def_basic_type_cmds<EventResponseHdlr>(pkg, SRC_POS);
00181 
00182   pkg->def_action("abortInvalidResponses",
00183                   &EventResponseHdlr::abortInvalidResponses,
00184                   SRC_POS);
00185   pkg->def_action("ignoreInvalidResponses",
00186                   &EventResponseHdlr::ignoreInvalidResponses,
00187                   SRC_POS);
00188   pkg->def_get_set("useFeedback",
00189                    &EventResponseHdlr::getUseFeedback,
00190                    &EventResponseHdlr::setUseFeedback,
00191                    SRC_POS);
00192   pkg->def_setter("inputResponseMap",
00193                   &EventResponseHdlr::setInputResponseMap,
00194                   SRC_POS);
00195   pkg->def_get_set("feedbackMap",
00196                    &EventResponseHdlr::getFeedbackMap,
00197                    &EventResponseHdlr::setFeedbackMap,
00198                    SRC_POS);
00199   pkg->def_get_set("eventSequence",
00200                    &EventResponseHdlr::getEventSequence,
00201                    &EventResponseHdlr::setEventSequence,
00202                    SRC_POS);
00203   pkg->def_get_set("bindingSubstitution",
00204                    &EventResponseHdlr::getBindingSubstitution,
00205                    &EventResponseHdlr::setBindingSubstitution,
00206                    SRC_POS);
00207   pkg->def("responseProc", "", &EventResponseHdlr::getResponseProc, SRC_POS);
00208   pkg->def("responseProc", "args body", &EventResponseHdlr::setResponseProc, SRC_POS);
00209   pkg->def_get_set("maxResponses",
00210                    &EventResponseHdlr::getMaxResponses,
00211                    &EventResponseHdlr::setMaxResponses,
00212                    SRC_POS);
00213 
00214   pkg->namesp_alias("EventRh");
00215 
00216   GVX_PKG_RETURN(pkg);
00217 }
00218 
00219 extern "C"
00220 int Kbdresponsehdlr_Init(Tcl_Interp* interp)
00221 {
00222 GVX_TRACE("Kbdresponsehdlr_Init");
00223 
00224   GVX_PKG_CREATE(pkg, interp, "KbdResponseHdlr", "4.$Revision: 10065 $");
00225   tcl::def_creator<KbdResponseHdlr>(pkg);
00226   pkg->inherit_pkg("EventResponseHdlr");
00227   tcl::def_basic_type_cmds<KbdResponseHdlr>(pkg, SRC_POS);
00228 
00229   pkg->namesp_alias("KbdRh");
00230 
00231   GVX_PKG_RETURN(pkg);
00232 }
00233 
00234 extern "C"
00235 int Nullresponsehdlr_Init(Tcl_Interp* interp)
00236 {
00237 GVX_TRACE("Nullresponsehdlr_Init");
00238 
00239   GVX_PKG_CREATE(pkg, interp, "NullResponseHdlr", "4.$Revision: 10065 $");
00240   tcl::def_creator<NullResponseHdlr>(pkg);
00241   pkg->inherit_pkg("ResponseHandler");
00242   tcl::def_basic_type_cmds<NullResponseHdlr>(pkg, SRC_POS);
00243   pkg->namesp_alias("NullRh");
00244 
00245   GVX_PKG_RETURN(pkg);
00246 }
00247 
00248 extern "C"
00249 int Serialrh_Init(Tcl_Interp* interp)
00250 {
00251 GVX_TRACE("Serialrh_Init");
00252 
00253   GVX_PKG_CREATE(pkg, interp, "SerialRh", "4.$Revision: 10065 $");
00254   pkg->def( "SerialRh::SerialRh", "device=/dev/tty0p0",
00255             rutz::bind_first(&startSerial, interp),
00256             SRC_POS );
00257   pkg->def( "SerialRh::SerialRh", "",
00258             rutz::bind_last(rutz::bind_first(&startSerial, interp),
00259                             "/dev/tty0p0"),
00260             SRC_POS );
00261 
00262   GVX_PKG_RETURN(pkg);
00263 }
00264 
00265 static const char __attribute__((used)) vcid_groovx_visx_tclpkg_rh_cc_utc20050628171008[] = "$Id: tclpkg-rh.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00266 #endif // !GROOVX_VISX_TCLPKG_RH_CC_UTC20050628171008_DEFINED