Warning, /graphics/kst-plot/devel-docs/plugins/KstCPlugins is written in an unsupported language. File is not indexed.
0001 ***************************************************************************** 0002 WARNING!!! These plugins are now deprecated. Plugin writers 0003 should instead consider writing such plugins by inheriting either 0004 KstDataObject or KstBasicPlugin. See the KstPlugin file for more info. 0005 ***************************************************************************** 0006 0007 KstCPlugin Plugins 0008 ------------ 0009 0010 Kst C plugins consist of two files, an XML file and a shared object. The XML 0011 file describes the contents of the shared object file. The shared object file 0012 contains the actual plugin code, and must export a C-style function. 0013 0014 XML FILE 0015 -------- 0016 0017 See linefit/linefit.xml for an example of an XML file. 0018 Each XML file contains an <intro> node with the following information: 0019 <modulename name="linefit"/> <!-- The name of the module --> 0020 <author name="George Staikos"/> <!-- The name of the author --> 0021 <description text="Generates a line of best fit for a set of data."/> 0022 <!-- A description of the module --> 0023 <version minor="1" major="0"/> <!-- The version number of the module --> 0024 <state devstate="release"/> <!-- The development state of the module --> 0025 0026 All but <state> are required. 0027 0028 The module also contains an <interface> node which describes the interface to 0029 the plugin. This node has children of type <input> and <output> for inputs 0030 and outputs respectively. It may contain any number of these, but they must 0031 be in the order that the plugin expects them. They are considered to be 0032 sequential inputs and outputs respectively. 0033 0034 Inputs and ouputs can be <table> or <float>. No other data types are 0035 supported at this time. All <table> nodes must be tables of floats. 0036 0037 An array input looks like this: 0038 <input> 0039 <table type="float" name="X Array" descr="The array of X coordinates." /> 0040 </input> 0041 A float (scalar) output looks like this: 0042 <output> 0043 <float name="a" descr="The a value in the interpolation equation y = a + b*x." /> 0044 </output> 0045 0046 0047 SHARED OBJECT 0048 ------------- 0049 0050 The shared object must export a C linkage symbol: 0051 int symbol(const double *const inArrays[], 0052 const int inArrayLens[], 0053 const double inScalars[], 0054 double *outArrays[], 0055 int outArrayLens[], 0056 double outScalars[]) 0057 0058 "symbol" would be the same as the attribute "name" of the node "modulename" in 0059 the XML file. The plugin must return 0 on success, or non-zero on error. It 0060 must be prepared to deal with inputs that are not what it expects (empty arrays, 0061 etc). Just return an error if that is the case. See below for a list of 0062 error codes. 0063 0064 If you return arrays, you must set outArrayLens[] appropriately. You must 0065 always return the exact number of arrays and scalars as the XML file indicates. 0066 outArrayLens[] will be set when your plugin is called, but you may need to 0067 resize the arrays. You must only do this with realloc(). Do not use any other 0068 memory allocator as it could cause internal memory problems in Kst. 0069 0070 Finally, do not, ever, cast away the constness of input variables. This will 0071 result in inconsistencies in Kst internally. The input variables are const for 0072 a reason and must remain as such. 0073 0074 0075 HOW TO BUILD THE C PLUGIN 0076 ----------------------- 0077 0078 If you write your plugin in C with GNU-style tools, you can compile your 0079 plugin like this: 0080 0081 cc -Wall -c -o myplugin.o myplugin.c -fPIC -DPIC 0082 ld -o myplugin.so -shared myplugin.o 0083 0084 0085 You should put the .so file and the .xml file in a common directory. Then the 0086 plugin manager in Kst can be used to browse to that directory and install the 0087 plugin in Kst automatically. 0088 0089 0090 0091 Matrices 0092 -------- 0093 0094 C Plugins can manipulate matrices by putting this in the XML file. In this case, 0095 two vectors will be exported in the vector lists, the first being the parameters 0096 of the matrix, the second being the entire matrix in a linear vector. 0097 0098 <matrix type="float" name="" descr=""/> 0099 0100 0101 Curve Hints 0102 ----------- 0103 0104 C Plugins can provide curve hints like this in the module node: 0105 <curvehints> 0106 <hint name="foo" x="xvectorname" y="yvectorname"/> 0107 </curvehints> 0108 0109 Note: Curve hints are automatically generated for filters, as defined below. 0110 0111 0112 Filters 0113 ------- 0114 0115 Filters are plugins that process a given input vector (along with one or more 0116 auxiliary vectors and scalars), and produce an output vector (along with one 0117 or more auxiliary vectors and scalars). The production of the output vector 0118 from the input vector is considered to be the main action of the plugin, and 0119 this simple definition allows filters to be easily added to vectors on the fly. 0120 A filter is marked by adding the following node to the intro node of the XML 0121 file: 0122 0123 <filter input="input_vector_name" output="output_vector_name" /> 0124 0125 0126 PID 0127 --- 0128 0129 A special input node can be specified of type "pid". This will be equivalent 0130 to a scalar but it receives the process ID of the main Kst process, since this 0131 is different than the one the plugin runs in. 0132 0133 0134 Localdata 0135 --------- 0136 0137 C Plugins that require the ability to store data across calls -cannot- use 0138 static memory. This would lead to race conditions and inconsistency. Instead, 0139 plugins must use a "localdata" facility. Simply specify the node <localdata /> 0140 in the intro node of the plugin XML file and change your plugin signature to 0141 this: 0142 int symbol(const double *const inArrays[], 0143 const int inArrayLens[], 0144 const double inScalars[], 0145 double *outArrays[], 0146 int outArrayLens[], 0147 double outScalars[], 0148 void **localdata) 0149 0150 On first call, this will be null. It is your responsibility to populate it 0151 with what you like, and it will be passed back to you on each call, with a 0152 separate one for each instance of the plugin in Kst. If you free() it, set 0153 it to null! For memory allocation, be sure to use only system malloc() and 0154 realloc(). 0155 0156 If you allocate something more than a simple free() can cleanup, you must clean 0157 up the localdata yourself. To do this, export a symbol: 0158 void freeLocalData(void**) 0159 that does the cleanup. It will be called when the plugin is being destroyed. 0160 0161 0162 Parameter Names 0163 --------------- 0164 Undocumented 0165 0166 0167 Error Codes 0168 ----------- 0169 > 0 Custom error, you must provide a symbol const char *errorCodes(int) which 0170 will be called to obtain a string representing the error. Make these 0171 strings static! 0172 -1 Generic error 0173 -2 Input error (something is wrong with the inputs) 0174 -3 Memory error (such as malloc failure) 0175 < -3 RESERVED