The SIMION SL™ Toolkit (version 1.2.1.0 - 2004-11-09)

SL Libraries -- C++

remote.h

Go to the documentation of this file.
00001 /** 00002 * @file remote.h 00003 * SL Remote interface (calling remote C++ subroutines from SL code) 00004 * 00005 * @author David Manura (c) 2003-2004 Scientific Instrument Services, Inc. 00006 * Licensed under the terms of the SIMION SL Toolkit. 00007 * $Revision: 1.3 $ $Date: 2004/07/17 20:23:07 $ Created 2003-11. 00008 */ 00009 00010 #ifndef SIMIONSL_SL_REMOTE_H 00011 #define SIMIONSL_SL_REMOTE_H 00012 00013 #include <vector> 00014 00015 namespace simion 00016 { 00017 00018 class SLRemote; 00019 class SLRemoteImpl_; 00020 00021 00022 /** 00023 * Prototype for callback functions. 00024 */ 00025 typedef void (*slremote_handler)(...); 00026 00027 /** 00028 * SL Remote class. 00029 * 00030 * This class forwards remote subroutines calls from SL 00031 * to subroutines in your C++ program. 00032 * 00033 * Calls are achieved essentially via an interprocess remote procedure 00034 * call (RPC). For those familiar, this is similar in concept, but 00035 * simpler than, other remote call mechanisms such as COM. 00036 * 00037 * SYNOPSIS 00038 * 00039 * Example C++ program: 00040 * 00041 * @code 00042 * #include <simion/remote.h> 00043 * //#include <simion/remote.cpp> 00044 * using namepace simion; 00045 * 00046 * void voltage_control(double tof, double& voltage_out) 00047 * { 00048 * if(tof > 1.0) { 00049 * voltage_out = 2; 00050 * } else { 00051 * voltage_out = tof; 00052 * } 00053 * } 00054 * void calculate(double x, double y, double& x_out, double& y_out) 00055 * { 00056 * x_out = x + 5; 00057 * y_out = y + 5; 00058 * } 00059 * 00060 * int main() 00061 * { 00062 * SLRemote remote; 00063 * remote.handler(1, slremote_handler(voltage_control)); 00064 * remote.handler(2, slremote_handler(calculate)); 00065 * remote.run(); 00066 * remote.wait_for_run_complete(); 00067 * return 0; 00068 * } 00069 * @endcode 00070 * 00071 * Corresponding SL program: 00072 * 00073 * @code 00074 * declaresub voltage_control(tof) returns(voltage_out) remote(1) 00075 * declaresub calculate(x,y) returns(x_out, y_out) remote(2) 00076 * 00077 * sub fast_adjust 00078 * adj_elect01 = voltage_control(ion_time_of_flight) 00079 * endsub 00080 * 00081 * sub other_actions 00082 * (x, y) = calculate(ion_px_mm, ion_py_mm) 00083 * print("#,#", x, y) 00084 * endsub 00085 * @endcode 00086 * 00087 * CAVEATS 00088 * 00089 * It is very important that the parameter lists of your 00090 * subroutines in your C++ code match those in your SL code. 00091 * Otherwise, the C++ code will likely crash. 00092 * 00093 * Be warned that interprocess communication calls are relatively time 00094 * consuming (e.g. 10-100x in CPU cycles compared to native code), 00095 * which becomes quite noticeable if you're doing thousands or 00096 * millions of them (e.g. multiple calls per timestep per ion, such as 00097 * in the fast_adjust segment). If this is the case, it is desirable 00098 * to limit the number of real-time remote calls, either by batching 00099 * multiple calls into a single call or implementing time-critical 00100 * sections of the code entirely in SL (which compiles to native PRG 00101 * code and is executed in-process). SL Remote works best when there 00102 * are a few expensive calls rather than voluminous inexpensive calls 00103 * into to C++ code. 00104 */ 00105 class SLRemote 00106 { 00107 public: 00108 /** 00109 * Constructs a new remoting object. 00110 */ 00111 SLRemote(); 00112 00113 /** 00114 * Destructor 00115 */ 00116 virtual ~SLRemote(); 00117 00118 /** 00119 * Registers a callback function and assigns it the given 00120 * remote ID. 00121 * When the SL code invokes the given remote ID, this 00122 * remoting object will in turn invoke the callback function 00123 * assigned to that remote ID. The remote ID specified here 00124 * and the remote ID specified in the SL code must match. 00125 */ 00126 void handler(int remote_id, slremote_handler handler); 00127 00128 /** 00129 * Starts up a new thread that listens and responds to 00130 * remote subroutines invoked from the SL code. 00131 * This method returns immediately, so you should then call 00132 * wait_for_run_complete() so that your program doesn't 00133 * immediately terminate. 00134 */ 00135 void run(); 00136 00137 /** 00138 * Waits for the thread created by the run() call to terminate. 00139 * Currently, this waits indefinitely unless debug tracing is enabled. 00140 * 00141 * (If debug tracing is enabled, SLRemote will terminate after a certain 00142 * number of idle seconds (currently 30) to output the debug log.) 00143 */ 00144 void wait_for_run_complete(); 00145 00146 /** 00147 * Turns debugging on/off. 00148 * @param val - true if on, else false. 00149 */ 00150 void debug_trace(bool val); 00151 00152 private: 00153 SLRemoteImpl_* p_; 00154 }; 00155 00156 00157 } // end namespace 00158 00159 #endif // first include 00160
(c) 2003-2004. Scientific Instrument Services, Inc. All Rights Reserved.
Please report any errors/comments regarding this web page:
  Name/e-mail/phone (optional):
 
The SIMION SL Toolkit™ and documentation is (c) 2003-2004 Scientific Instrument Services, Inc. All Rights Reserved.