TSP: The Transport Sample Protocol



Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

gdisp_kernel.h

Go to the documentation of this file.
00001 
00043 #ifndef __KERNEL_H__
00044 #define __KERNEL_H__
00045 
00046 #include <gtk/gtk.h>
00047 #include <pthread.h>
00048 
00049 
00050 /*
00051  * TSP Consumer include.
00052  * Definitition of a dynamic array of double.
00053  */
00054 #include "tsp_const_def.h"
00055 #include "tsp_consumer.h"
00056 #include "gdisp_doubleArray.h"
00057 
00058 
00059 /*
00060  * Define this to enable Drag And Drop debug.
00061  */
00062 #undef _DND_DEBUG_
00063 
00064 
00065 /*
00066  * 10 out of 170 colors.
00067  */
00068 #define _RED_       3
00069 #define _GREEN_    10
00070 #define _ORANGE_   14
00071 #define _YELLOW_   17
00072 #define _BLUE_     24
00073 #define _MAGENTA_  31
00074 #define _CYAN_     38
00075 #define _BLACK_    42
00076 #define _GREY_    155
00077 #define _WHITE_   169
00078 
00079 
00080 /*
00081  * A message may be a simple message, a warning or an information
00082  * reporting a error.
00083  */
00084 typedef enum {
00085 
00086   GD_MESSAGE = 0,
00087   GD_WARNING,
00088   GD_ERROR
00089 
00090 } Message_T;
00091 
00092 
00093 /*
00094  * Time management.
00095  * Everything below is expressed in 'nanoseconds'.
00096  */
00097 typedef gint64 HRTime_T;
00098 
00099 #define GDISP_SYSTEM_HAVE_NANOSLEEP
00100 
00101 #define _10_MILLISECONDS_IN_NANOSECONDS_       10000000LL
00102 #define _100_MILLISECONDS_IN_NANOSECONDS_     100000000LL
00103 #define _250_MILLISECONDS_IN_NANOSECONDS_     250000000LL
00104 #define _ONE_SECOND_IN_NANOSECONDS_          1000000000LL
00105 
00106 #define _10_MILLISECONDS_IN_MICROSECONDS_         10000LL
00107 #define _100_MILLISECONDS_IN_MICROSECONDS_       100000LL
00108 #define _250_MILLISECONDS_IN_MICROSECONDS_       250000LL
00109 #define _ONE_SECOND_IN_MICROSECONDS_            1000000LL
00110 
00111 
00112 /*
00113  * HOST management.
00114  * Few things by now... be patient...
00115  */
00116 typedef struct Host_T_ {
00117 
00118   GString *hName;
00119   
00120 } Host_T;
00121 
00122 
00123 /*
00124  * TSP provider management.
00125  * Available provider statuses :
00126  *  - FROM_SCRATCH
00127  *      The provider has just been created. Nothing can be done with it.
00128  *  - SESSION_CLOSED
00129  *      The provider has now its name.
00130  *      But 'TSP_consumer_request_*' functions can not be called yet.
00131  *  - SESSION_OPENED
00132  *      Ready now to request any information of the provider.
00133  *  - SAMPLE_REQUESTED
00134  *      The provider has been given the set of symbols to be sampled.
00135  *      But 'sampling' is still OFF.
00136  *  - SAMPLE_STARTED
00137  *      'sampling' is now ON.
00138  */
00139 typedef enum {
00140 
00141   GD_FROM_SCRATCH = 0,
00142   GD_SESSION_CLOSED,
00143   GD_SESSION_OPENED,
00144   GD_SAMPLE_REQUESTED,
00145   GD_SAMPLE_STARTED
00146 
00147 } ProviderStatus_T;
00148 
00149 
00150 /*
00151  * Ha Ha...
00152  * Here is now the description of what a symbol looks like within GDisp+.
00153  *  - sReference  : must be incremented each time the symbol is dropped on
00154  *                  a graphic plot. It is up to graphic plots to increment
00155  *                  the 'sReference' variable, and to decrement it each time
00156  *                  the symbol is no longer requested by the plot.
00157  *  - sInfo       : structure coming from TSP core.
00158  *                  contains : name, index, period and phase.
00159  *  - sLastValue  : the double precision value of the symbol.
00160  *  - sTimeTag    : the time tag of the symbol value.
00161  *  - sHasChanged : has this symbol evolved since last frame ?
00162  */
00163 
00164 /* FIXME : the following three definitions must be dynamic */
00165 #define TSP_PROVIDER_FREQ     100   /* Hz                */
00166 #define GDISP_REFRESH_FREQ     10   /* Hz                */
00167 #define GDISP_WIN_T_DURATION  100   /* Seconds on X Axis */
00168 
00169 typedef struct Symbol_T_ {
00170 
00171   guchar                           sReference;
00172   TSP_consumer_symbol_requested_t  sInfo;
00173   guint                            sTimeTag;
00174   gdouble                          sLastValue;
00175   gboolean                         sHasChanged;
00176 
00177   /*
00178    * Graphic.
00179    */
00180   GtkCTreeNode                    *sNode;
00181 
00182 } Symbol_T;
00183 
00184 
00185 /*
00186  * When showing all available symbols into a Gtk CList,
00187  * try to sort these symbols with different manners.
00188  */
00189 typedef enum {
00190 
00191   GD_SORT_BY_NAME = 0,
00192   GD_SORT_BY_NAME_REVERSE,
00193   GD_SORT_BY_PROVIDER,
00194   GD_SORT_BY_STRING
00195 
00196 } SortingMethod_T;
00197 
00198 
00199 /*
00200  * When droping a set of symbols (DnD Action on graphic plot),
00201  * does the drop action be broadcast to all graphic plots ?
00202  *   - GD_DND_UNICAST   : Only one graphic plot,
00203  *   - GD_DND_MULTICAST : All graphic plots of the current page,
00204  *   - GD_DND_BROADCAST : All graphic plots of all existing graphic pages.
00205  */
00206 typedef enum {
00207 
00208   GD_DND_UNICAST = 0,
00209   GD_DND_MULTICAST,
00210   GD_DND_BROADCAST
00211 
00212 } DndScope_T;
00213 
00214 
00215 /*
00216  * Shorter name for symbol that must be sampled.
00217  */
00218 typedef TSP_consumer_symbol_requested_list_t SampleList_T;
00219 
00220 
00221 /*
00222  * Thread Status.
00223  */
00224 typedef enum {
00225 
00226   GD_THREAD_STOPPED = 0,
00227   GD_THREAD_STARTING,
00228   GD_THREAD_WARNING,
00229   GD_THREAD_REQUEST_SAMPLE_ERROR,
00230   GD_THREAD_SAMPLE_INIT_ERROR,
00231   GD_THREAD_SAMPLE_DESTROY_ERROR,
00232   GD_THREAD_ERROR,
00233   GD_THREAD_RUNNING
00234 
00235 } ThreadStatus_T;
00236 
00237 
00238 /*
00239  * A TSP provider definition.
00240  *
00241  * The number of provider is limited because I have only 6 ball pixmaps
00242  * to represent them. That's all. There is no other reason.
00243  * Theorically, there is no limit, except the number of ball pixmaps.
00244  * Feel free to create other ball pixmaps...
00245  */
00246 #define GD_MAX_PROVIDER_NUMBER 6
00247 
00248 typedef struct Provider_T_ {
00249 
00250   TSP_provider_t    pHandle;
00251   guint             pIdentity;
00252 
00253   ProviderStatus_T  pStatus;
00254   GString          *pUrl;
00255   gdouble           pBaseFrequency;
00256   gint              pMaxPeriod;
00257   gint              pMaxClientNumber;
00258   gint              pCurrentClientNumber;
00259 
00260   gint              pSymbolNumber;
00261   Symbol_T         *pSymbolList;
00262 
00263   SampleList_T      pSampleList;
00264   guint             pLoad;
00265   guint             pMaxLoad;
00266 
00267   /*
00268    * Thread management.
00269    */
00270   pthread_t         pSamplingThread;
00271   ThreadStatus_T    pSamplingThreadStatus;
00272 
00273   /*
00274    * Graphic information.
00275    */
00276   GtkWidget        *pCList;
00277   GdkColor         *pColor;
00278   GtkCTreeNode     *pNode;
00279 
00280 } Provider_T;
00281 
00282 
00283 /*
00284  * Plot types.
00285  *  - GD_PLOT_DEFAULT : when the graphic page has just been created.
00286  *  - GD_PLOT_2D      : y = f(t) or y = f(x)
00287  *  - GD_PLOT_2D5     : z = f(x,y)
00288  *  - GD_PLOT_3D      : full colored tri-dimensional object.
00289  */
00290 typedef enum {
00291 
00292   GD_PLOT_DEFAULT = 0,
00293   GD_PLOT_TEXT,
00294   GD_PLOT_2D,
00295   GD_PLOT_2D5,
00296   GD_PLOT_3D,
00297   GD_MAX_PLOT /* this last one defines the limit */
00298 
00299 } PlotType_T;
00300 
00301 
00302 /*
00303  * Font management.
00304  */
00305 typedef enum {
00306 
00307   GD_FONT_NORMAL = 0,
00308   GD_FONT_ITALIC,
00309   GD_FONT_FIXED,
00310   GD_FONT_MAX_TYPE
00311 
00312 } FontType_T;
00313 
00314 typedef enum {
00315 
00316   GD_FONT_SMALL = 0,
00317   GD_FONT_MEDIUM,
00318   GD_FONT_BIG,
00319   GD_FONT_MAX_SIZE
00320 
00321 } FontSize_T;
00322 
00323 
00324 /*
00325  * Kernel alias.
00326  */
00327 typedef struct Kernel_T_ *Kernel_T_Ptr;
00328 
00329 
00330 /*
00331  * Definition of the operating system of a given typed plot.
00332  */
00333 typedef void*        aFunction_T;
00334 typedef aFunction_T *FunctionTable_T;
00335 
00336 typedef struct PlotSystemInfo_T_ {
00337 
00338   gchar  *psName;
00339   gchar  *psFormula;
00340   gchar  *psDescription;
00341   gchar **psLogo;
00342 
00343 } PlotSystemInfo_T;
00344 
00345 typedef struct PlotSystemZone_T_ {
00346 
00347 #define GD_ZONE_MAX_POINTS 5
00348   guchar     pszId; /* different from 0 in order to be valid */
00349   gdouble    pszX[GD_ZONE_MAX_POINTS];
00350   gdouble    pszY[GD_ZONE_MAX_POINTS];
00351   guint      pszPointNb;
00352   gchar    **pszIcon;
00353   gboolean   pszAcceptDrops;
00354   gchar     *pszComment;
00355 
00356 } PlotSystemZone_T;
00357 
00358 typedef struct PlotSystem_T_ {
00359 
00360   /* DO NOT PUT ANYTHING BEFORE THE FOLLOWING FUNCTIONS     */
00361   /* See 'gdisp_kernel.c' when checking plot system support */
00362 
00363   /*
00364    * All that is needed to manage a plot system.
00365    * Two types of functions :
00366    *  - The first ones MUST not rely on a 'void*' argument that may be
00367    *    the opaque structure of a plot. Only the kernel is given.
00368    *  - The other ones can rely on the kernel AND the opaque structure
00369    *    of the plot.
00370    */
00371 
00372   /* FIRST TYPE : Kernel only.                  */
00373   void       (*psGetInformation)   (Kernel_T_Ptr,PlotSystemInfo_T*  );
00374   void      *(*psCreate )          (Kernel_T_Ptr                    );
00375   GArray    *(*psGetDropZones)     (Kernel_T_Ptr                    );
00376 
00377   /* SECOND TYPE : Kernel and opaque structure. */
00378   void       (*psDestroy)          (Kernel_T_Ptr,void*              );
00379   void       (*psSetParent)        (Kernel_T_Ptr,void*,GtkWidget*   );
00380   GtkWidget *(*psGetTopLevelWidget)(Kernel_T_Ptr,void*              );
00381   void       (*psShow)             (Kernel_T_Ptr,void*              );
00382   PlotType_T (*psGetType)          (Kernel_T_Ptr,void*              );
00383   void       (*psSetDimensions)    (Kernel_T_Ptr,void*,guint,guint  );
00384   void       (*psAddSymbols)       (Kernel_T_Ptr,void*,GList*,guchar);
00385   GList     *(*psGetSymbols)       (Kernel_T_Ptr,void*,gchar        );
00386   gboolean   (*psStartStep)        (Kernel_T_Ptr,void*              );
00387   void       (*psStep)             (Kernel_T_Ptr,void*              );
00388   void       (*psStopStep)         (Kernel_T_Ptr,void*              );
00389   void       (*psTreatSymbolValues)(Kernel_T_Ptr,void*              );
00390   guint      (*psGetPeriod)        (Kernel_T_Ptr,void*              );
00391 
00392   /*
00393    * Kernel verification.
00394    */
00395   gboolean     psIsSupported;
00396 
00397 } PlotSystem_T;
00398 
00399 
00400 /*
00401  * Data associated to each graphic plot on a graphic page.
00402  */
00403 typedef struct PlotSystemData_T_ {
00404 
00405   PlotSystem_T *plotSystem;
00406   void         *plotData;
00407   guint         plotCycle;
00408   
00409 } PlotSystemData_T;
00410 
00411 
00412 /*
00413  * A Graphic Page.
00414  */
00415 typedef struct Page_T_ {
00416 
00417   /*
00418    * Dimensions and name.
00419    */
00420   guchar            pRows;
00421   guchar            pColumns;
00422   GString          *pName;
00423 
00424   /*
00425    * Plot system data (size is 'pRows' x 'pColumns').
00426    */
00427   PlotSystemData_T *pPlotSystemData;
00428 
00429   /*
00430    * Graphic widgets.
00431    */
00432   GtkWidget        *pWindow;
00433   GtkWidget        *pTable;
00434 
00435 } Page_T;
00436 
00437 
00438 /*
00439  * A structure that hols all GtkWidgets that must be recorded in order
00440  * to manage all top-level callbacks.
00441  */
00442 #include "gdisp_pixmaps.h"
00443 
00444 typedef struct KernelWidget_T_ {
00445 
00446   GtkWidget         *mainBoardWindow;
00447   GtkWidget         *mainBoardOkButton;
00448   GtkWidget         *mainBoardStopButton;
00449   GtkWidget         *mainBoardOutputList;
00450   guint              mainBoardOutputListSize;
00451   Pixmap_T          *pilotBoardDigitPixmap;
00452   GtkWidget         *pilotBoardTimeArea;
00453   GdkGC             *pilotBoardTimeContext;
00454   GtkWidget         *dataBookWindow;
00455   GtkWidget         *dataBookWidget;
00456   GtkWidget         *dataBookApplyButton;
00457 #define _SYMBOL_CLIST_COLUMNS_NB_ 3
00458   GtkWidget         *symbolCList;
00459   GtkWidget         *symbolFrame;
00460   GtkWidget         *pRadioButton;
00461   GtkWidget         *naRadioButton;
00462   GtkWidget         *ndRadioButton;
00463   GtkWidget         *uRadioButton;
00464   GtkWidget         *spRadioButton;
00465   GtkWidget         *apRadioButton;
00466   GtkWidget         *filterEntry;
00467   GtkStyle          *selectedNodeStyle;
00468   GtkStyle          *unselectedNodeStyle;
00469   Pixmap_T          *expandedNodePixmap;
00470   Pixmap_T          *collapsedNodePixmap;
00471   GtkWidget         *sampledSymbolHTree;
00472 
00473   GList             *pixmapTable;
00474 
00475 } KernelWidget_T;
00476 
00477 
00478 /*
00479  * Kernel structure.
00480  */
00481 typedef struct Kernel_T_ {
00482 
00483   /*
00484    * GDISP+ Kernel Information.
00485    */
00486   gint               argCounter;
00487   gchar            **argTable;
00488 
00489   /*
00490    * GTK timer identity and period in milli-seconds.
00491    */
00492   gint               stepTimerIdentity;
00493 #define GD_TIMER_MIN_PERIOD 100
00494   guint              stepTimerPeriod;
00495   guint              stepGlobalCycle;
00496   gint               kernelTimerIdentity;
00497   GPtrArray         *kernelRegisteredActions;
00498 
00499   /*
00500    * Definition of the multi-threaded environment.
00501    */
00502   gboolean           isThreadSafe;
00503   void            *(*mutexNew)    (void);
00504   void             (*mutexLock)   (Kernel_T_Ptr,void*);
00505   gboolean         (*mutexTrylock)(Kernel_T_Ptr,void*);
00506   void             (*mutexUnlock) (Kernel_T_Ptr,void*);
00507   void             (*mutexFree)   (Kernel_T_Ptr,void*);
00508 
00509   /*
00510    * Sampling thread and attributes.
00511    */
00512   gboolean           samplingThreadMustExit;
00513   pthread_t          garbageCollectorThread;
00514 
00515   /*
00516    * Useful functions available in the kernel.
00517    */
00518   void             (*outputFunc)              (Kernel_T_Ptr,
00519                                                GString*,
00520                                                Message_T);
00521   void             (*registerAction)          (Kernel_T_Ptr,
00522                                                void(*action)(Kernel_T_Ptr));
00523   void             (*unRegisterAction)        (Kernel_T_Ptr,
00524                                                void(*action)(Kernel_T_Ptr));
00525   void             (*assignSymbolsToProviders)(Kernel_T_Ptr);
00526 
00527   /*
00528    * Host/URL management.
00529    */
00530   GList             *hostList;
00531   GList             *urlList;
00532 
00533   /*
00534    * Provider management.
00535    */
00536   GList             *providerList;
00537   SortingMethod_T    sortingMethod;
00538 
00539 
00540   /*
00541    * -------------------- Graphic part --------------------
00542    */
00543 
00544   /*
00545    * Colormap and color management.
00546    */
00547   GdkColormap       *colormap;
00548   GdkVisual         *visual;
00549   GdkColor          *colors;
00550   gint               colorNumber;
00551   GdkFont           *fonts[GD_FONT_MAX_SIZE][GD_FONT_MAX_TYPE];
00552 
00553   /*
00554    * Definition of all available plot systems.
00555    */
00556   PlotSystem_T       plotSystems[GD_MAX_PLOT];
00557   PlotType_T         currentPlotType;
00558 
00559   /*
00560    * Graphic pages.
00561    */
00562   GList             *pageList;
00563 
00564   /*
00565    * Drag & Dop process.
00566    */
00567   GList             *dndSelection;
00568   DndScope_T         dndScope;
00569   GdkWindow         *dndIconWindow;
00570   GdkWindow         *dndIconWindowParent;
00571   GdkGC             *dndIconWindowGc;
00572   GdkPixmap         *dndIconPixmap;
00573   GdkBitmap         *dndIconPixmapMask;
00574 
00575   /*
00576    * Widget management.
00577    */
00578   KernelWidget_T     widgets;
00579 
00580 } Kernel_T;
00581 
00582 
00583 #endif /* __KERNEL_H__ */
Framework Home Page.

Beware !! TSP wave is coming...