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

Last change on this file since 65 was 65, checked in by Torben Dannhauer, 14 years ago

new cluster implementation added: ENet
ENet is a reliable UDP implementation with quite simple usage and high performance for transmission with small or medium size packet.

File size: 5.2 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// Cluster einbinden
25#ifdef USE_CLUSTER_ASIO_TCP_IOSTREAM
26        #include <dataIO_clusterAsioTcpIostream.h>
27#endif
28#ifdef USE_CLUSTER_DUMMY
29        #include <dataIO_clusterDummy.h>
30#endif
31#ifdef USE_CLUSTER_UDP
32        #include <dataIO_clusterUDP.h>
33#endif
34#ifdef USE_CLUSTER_ENET
35        #include <dataIO_clusterENet.h>
36#endif
37
38
39//ExtLink einbinden
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#include <vector>
53
54
55
56
57namespace osgVisual {
58
59/**
60 * \brief Zentrale Klasse für Datenanbindung des Sichtsystemnodes an das Gesamtsichtsystem bzw. dem Simulator.
61 *
62 * Damit nur eine Klasse instantiiert werden kann, ist diese Klasse als Singleton realisiert.
63 *
64 *
65 * @author Torben Dannhauer
66 * @date  Nov 2009
67 */ 
68class visual_dataIO : public osg::Referenced
69{
70private:
71        class dataIO_eventCallback : public osg::NodeCallback
72        {
73        public: 
74                /**
75                 * \brief Constructor, for setting the member variables.
76                 *
77                 * @param viewer_ : Pointer to the viewer.
78                 * @param sceneCamera_ : Pointer to the scene camera.
79                 */ 
80                dataIO_eventCallback(visual_dataIO* dataIO_):dataIO(dataIO_){};
81
82                /**
83                 * \brief This function is execute d as callback during update traversal.
84                 *
85                 */ 
86                virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
87        private:
88                visual_dataIO* dataIO;
89        };
90        osg::ref_ptr<dataIO_eventCallback> eventCallback;
91
92
93        class dataIO_finalDrawCallback : public osg::Camera::DrawCallback
94        {
95        public:
96                /**
97                 * \brief Constructor
98                 *
99                 */ 
100                dataIO_finalDrawCallback::dataIO_finalDrawCallback(visual_dataIO* dataIO_):dataIO(dataIO_){};
101               
102                /**
103                 * \brief Operator executed at callback
104                 *
105                 */ 
106                virtual void operator () (const osg::Camera& camera) const;
107        private:
108                visual_dataIO* dataIO;
109        };
110
111        osg::ref_ptr<dataIO_finalDrawCallback> finalDrawCallback;
112
113        // Make Constructor private to prevent creating instances via ptr* = new ..().
114        visual_dataIO();
115        // Make Copy-Constructor private to prevent getting instances via copying dataIO instance.
116        visual_dataIO(const visual_dataIO& cc);
117
118        osg::ref_ptr<dataIO_extLink> extLink;
119        osg::ref_ptr<dataIO_cluster> cluster;
120
121        /**
122         * Referenced Pointer to the applications viewer.
123         */ 
124        osg::ref_ptr<osgViewer::Viewer> viewer;
125
126        osg::ref_ptr<osgVisual::dataIO_transportContainer> slotContainer;
127
128        /**
129         * List of SLOT variables dataIO provides.
130         */ 
131        std::vector<dataIO_slot> dataSlots;
132
133        friend dataIO_eventCallback;
134        friend dataIO_finalDrawCallback;
135
136public:
137        // Public destructor to allow singleton cleanup from extern
138        ~visual_dataIO();
139
140        /**
141         * \brief This function returns an pointer to the singleton instalce of dataIO. If now instance exist, it will be instantiated silently.
142         *
143         * After instantiation, dataIO still needs to bei initiialized to configure working mode etc!
144         *
145         * @return : Pointer to the instance.
146         */ 
147        static visual_dataIO* getInstance();
148
149        void init(osgViewer::Viewer* viewer_,osg::ArgumentParser& arguments_);
150        void shutdown();
151        bool isMaster(){if (clusterMode==osgVisual::dataIO_cluster::MASTER) return true; else return false;};
152        bool isSlave(){if (clusterMode==osgVisual::dataIO_cluster::SLAVE) return true; else return false;};
153        bool isStandalone(){if (clusterMode==osgVisual::dataIO_cluster::STANDALONE) return true; else return false;};
154
155
156// SLOT Access functions
157        void* getSlotPointer(std::string slotName_, osgVisual::dataIO_slot::dataDirection direction_, osgVisual::dataIO_slot::varType variableTyp_ );
158        double getSlotDataAsDouble(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_ );
159        std::string getSlotDataAsString(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_ );
160        void setSlotData(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_, std::string sValue_ );
161        void setSlotData(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_, double value_ );
162
163        int getSlotNum() {return dataSlots.size();}
164
165        osgVisual::dataIO_cluster::clustermode clusterMode;
166
167        bool initialized;
168};
169
170
171} // END namespace osgVisual
Note: See TracBrowser for help on using the repository browser.