source: osgVisual/include/dataIO/visual_dataIO.h @ 160

Last change on this file since 160 was 160, checked in by Torben Dannhauer, 13 years ago

change dataIO configuration from command line to xml File.

Status: in Progress

File size: 6.5 KB
Line 
1#pragma once
2/* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer
3 *
4 * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under
5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 * (at your option) any later version.  The full license is in LICENSE file
7 * included with this distribution, and on the openscenegraph.org website.
8 *
9 * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
10 * You have to aquire licenses for all used proprietary modules.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * OpenSceneGraph Public License for more details.
16*/
17
18#include <osg/Notify>
19#include <osg/Referenced>
20#include <osg/ArgumentParser>
21
22#include <osgViewer/Viewer>
23
24// osgVisual specifiy includes
25#include <visual_util.h>
26
27// Cluster
28#ifdef USE_CLUSTER_ASIO_TCP_IOSTREAM
29        #include <dataIO_clusterAsioTcpIostream.h>
30#endif
31#ifdef USE_CLUSTER_ENET
32        #include <dataIO_clusterENet.h>
33#endif
34#ifdef USE_CLUSTER_DUMMY
35        #include <dataIO_clusterDummy.h>
36#endif
37
38
39//ExtLink
40#ifdef USE_EXTLINK_DUMMY
41        #include <dataIO_extLinkDummy.h>
42#endif
43#ifdef USE_EXTLINK_VCL
44        #include <dataIO_extLinkVCL.h>
45#endif
46
47
48// Slot and transportContainer definitions
49#include <dataIO_slot.h>
50#include <dataIO_transportContainer.h>
51
52// XML Parser
53#include <stdio.h>
54#include <libxml/parser.h>
55#include <libxml/tree.h>
56
57// C++ stl libraries
58#include <vector>
59
60
61
62
63namespace osgVisual {
64
65/**
66 * \brief Zentrale Klasse für Datenanbindung des Sichtsystemnodes an das Gesamtsichtsystem bzw. dem Simulator.
67 *
68 * Damit nur eine Klasse instantiiert werden kann, ist diese Klasse als Singleton realisiert.
69 *
70 *
71 * @author Torben Dannhauer
72 * @date  Nov 2009
73 */ 
74class visual_dataIO : public osg::Referenced
75{
76        #include <leakDetection.h>
77private:
78        class dataIO_eventCallback : public osg::NodeCallback
79        {
80        public: 
81                /**
82                 * \brief Constructor, for setting the member variables.
83                 *
84                 * @param viewer_ : Pointer to the viewer.
85                 * @param sceneCamera_ : Pointer to the scene camera.
86                 */ 
87                dataIO_eventCallback(visual_dataIO* dataIO_):dataIO(dataIO_){};
88
89                /**
90                 * \brief This function is execute d as callback during update traversal.
91                 *
92                 */ 
93                virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
94        private:
95                visual_dataIO* dataIO;
96        };
97        osg::ref_ptr<dataIO_eventCallback> eventCallback;
98
99        class dataIO_finalDrawCallback : public osg::Camera::DrawCallback
100        {
101        public:
102                /**
103                 * \brief Constructor
104                 *
105                 */ 
106                dataIO_finalDrawCallback(visual_dataIO* dataIO_):dataIO(dataIO_){};
107               
108                /**
109                 * \brief Operator executed at callback
110                 *
111                 */ 
112                virtual void operator () (const osg::Camera& camera) const;
113        private:
114                visual_dataIO* dataIO;
115        };
116
117        osg::ref_ptr<dataIO_finalDrawCallback> finalDrawCallback;
118
119        /**
120         * \brief Constructor: It is private to prevent creating instances via ptr* = new ..().
121         *
122         */ 
123        visual_dataIO();
124
125        /**
126         * \brief Copy-Constuctor: It is private to prevent getting instances via copying dataIO instance.
127         *
128         * @param cc : Instance to copy from.
129         */ 
130        visual_dataIO(const visual_dataIO& cc);
131
132        /**
133         * \brief This function parses the XML config file for dataIO relevant parameters.
134         *
135         * @return : True if parsing was successful.
136         */ 
137        bool processXMLConfiguration(); 
138
139        /**
140         * \brief Todo: required?
141         *
142         * @return
143         */ 
144        osg::Matrixd calcViewMatrix();
145
146        /**
147         * Pointer to the base class of the extLink implementation.
148         */ 
149        osg::ref_ptr<dataIO_extLink> extLink;
150
151        /**
152         * Pointer to the base class of the cluster implementation.
153         */ 
154        osg::ref_ptr<dataIO_cluster> cluster;
155
156        /**
157         * Referenced pointer to the applications viewer.
158         */ 
159        osg::ref_ptr<osgViewer::Viewer> viewer;
160
161        /**
162         * Referenced pointer transport contained user to transport the set of all slots to all rendering machines.
163         */ 
164        osg::ref_ptr<osgVisual::dataIO_transportContainer> slotContainer;
165
166        /**
167         * List of SLOT variables dataIO provides.
168         */ 
169        std::vector<dataIO_slot*> dataSlots;
170
171        /**
172         * Flag to indicate if dataIO is initialized.
173         */ 
174        bool initialized;
175
176        /**
177         * Curent clustermode of the application. Can be MASTER, SLAVE or STANDALONE.
178         */ 
179        osgVisual::dataIO_cluster::clustermode clusterMode;
180
181        /**
182         * XML config filename
183         */ 
184        std::string configFileName;
185
186        /**
187         * The eventCallback-class is friend to be able to work with all dataIO members without setters/getters.
188         */ 
189        friend class dataIO_eventCallback;
190
191        /**
192         *  The FinalDrawCallback-class is friend to be able to work with all dataIO members without setters/getters.
193         */ 
194        friend class dataIO_finalDrawCallback;
195
196public:
197        /**
198         * \brief Public destructor to allow singleton cleanup from extern
199         *
200         */ 
201        ~visual_dataIO();
202
203        /**
204         * \brief This function returns an pointer to the singleton instance of dataIO. If no instance exist, it will be instantiated silently.
205         *
206         * After instantiation, dataIO still needs to bei initiialized to configure working mode etc!
207         *
208         * @return : Pointer to the instance.
209         */ 
210        static visual_dataIO* getInstance();
211
212        void init(osgViewer::Viewer* viewer_,osg::ArgumentParser& arguments_, std::string configFileName);
213        void shutdown();
214        bool isMaster(){if (clusterMode==osgVisual::dataIO_cluster::MASTER) return true; else return false;};
215        bool isSlave(){if (clusterMode==osgVisual::dataIO_cluster::SLAVE) return true; else return false;};
216        bool isStandalone(){if (clusterMode==osgVisual::dataIO_cluster::STANDALONE) return true; else return false;};
217
218// SLOT Access functions
219        void* getSlotPointer(std::string slotName_, osgVisual::dataIO_slot::dataDirection direction_, osgVisual::dataIO_slot::varType variableTyp_ );
220        double getSlotDataAsDouble(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_ );
221        std::string getSlotDataAsString(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_ );
222        osgVisual::dataIO_slot* setSlotData(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_, std::string sValue_ );
223        osgVisual::dataIO_slot* setSlotData(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_, double value_ );
224
225        int getSlotNum() {return dataSlots.size();}
226
227};
228
229
230} // END namespace osgVisual
Note: See TracBrowser for help on using the repository browser.