1 /**************************************************************************\
2 * Copyright (c) Kongsberg Oil & Gas Technologies AS
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32
33 #include <Inventor/navigation/SoScXMLNavigation.h>
34
35 /*!
36 \class SoScXMLNavigation SoScXMLNavigation.h Inventor/scxml/SoScXMLNavigation.h
37 \brief Static class for some static init/cleanup/synchronization functions.
38
39 \ingroup navigation
40 */
41
42 #include <cassert>
43 #include "tidbitsp.h"
44
45 #include <Inventor/misc/CoinResources.h>
46 #include <Inventor/errors/SoDebugError.h>
47 #include <Inventor/navigation/SoScXMLRotateTarget.h>
48 #include <Inventor/navigation/SoScXMLPanTarget.h>
49 #include <Inventor/navigation/SoScXMLZoomTarget.h>
50 #include <Inventor/navigation/SoScXMLDollyTarget.h>
51 #include <Inventor/navigation/SoScXMLSpinTarget.h>
52 #include <Inventor/navigation/SoScXMLSeekTarget.h>
53 #include <Inventor/navigation/SoScXMLMiscTarget.h>
54 #include <Inventor/navigation/SoScXMLFlightControlTarget.h>
55 #include <Inventor/navigation/SoScXMLMotionTarget.h>
56 #include <Inventor/C/threads/mutex.h>
57 #include "threads/threadsutilp.h"
58 #include "navigation/common-xml.cpp"
59 #include "navigation/examiner-xml.cpp"
60 #include "navigation/plane-xml.cpp"
61
62 class SoScXMLNavigation::PImpl {
63 public:
64 static void * syncmutex;
65 };
66
67 void * SoScXMLNavigation::PImpl::syncmutex = NULL;
68
69 void
initClasses(void)70 SoScXMLNavigation::initClasses(void)
71 {
72 assert(PImpl::syncmutex == NULL);
73 CC_MUTEX_CONSTRUCT(PImpl::syncmutex);
74
75 SoScXMLNavigationTarget::initClass();
76 SoScXMLRotateTarget::initClass();
77 SoScXMLSpinTarget::initClass();
78 SoScXMLPanTarget::initClass();
79 SoScXMLZoomTarget::initClass();
80 SoScXMLDollyTarget::initClass();
81 SoScXMLSeekTarget::initClass();
82 SoScXMLMiscTarget::initClass();
83 SoScXMLFlightControlTarget::initClass();
84 SoScXMLMotionTarget::initClass();
85
86 CoinResources::set("coin:scxml/navigation/common.xml",
87 SbByteBuffer(sizeof(common_xml)-1,&common_xml[0]));
88
89 CoinResources::set("coin:scxml/navigation/examiner.xml",
90 SbByteBuffer(sizeof(examiner_xml)-1,&examiner_xml[0]));
91
92 CoinResources::set("coin:scxml/navigation/plane.xml",
93 SbByteBuffer(sizeof(plane_xml)-1,&plane_xml[0]));
94
95 // launch services
96 SoScXMLRotateTarget::constructSingleton();
97 SoScXMLPanTarget::constructSingleton();
98 SoScXMLZoomTarget::constructSingleton();
99 SoScXMLDollyTarget::constructSingleton();
100 SoScXMLSpinTarget::constructSingleton();
101 SoScXMLSeekTarget::constructSingleton();
102 SoScXMLMiscTarget::constructSingleton();
103 SoScXMLFlightControlTarget::constructSingleton();
104 SoScXMLMotionTarget::constructSingleton();
105
106 coin_atexit(reinterpret_cast<coin_atexit_f*>(SoScXMLNavigation::cleanClasses), CC_ATEXIT_NORMAL);
107 }
108
109 void
cleanClasses(void)110 SoScXMLNavigation::cleanClasses(void)
111 {
112 SoScXMLMotionTarget::destructSingleton();
113 SoScXMLFlightControlTarget::destructSingleton();
114 SoScXMLMiscTarget::destructSingleton();
115 SoScXMLSeekTarget::destructSingleton();
116 SoScXMLSpinTarget::destructSingleton();
117 SoScXMLDollyTarget::destructSingleton();
118 SoScXMLZoomTarget::destructSingleton();
119 SoScXMLPanTarget::destructSingleton();
120 SoScXMLRotateTarget::destructSingleton();
121
122 SoScXMLRotateTarget::cleanClass();
123 SoScXMLSpinTarget::cleanClass();
124 SoScXMLPanTarget::cleanClass();
125 SoScXMLDollyTarget::cleanClass();
126 SoScXMLZoomTarget::cleanClass();
127 SoScXMLSeekTarget::cleanClass();
128 SoScXMLMiscTarget::cleanClass();
129 SoScXMLFlightControlTarget::cleanClass();
130 SoScXMLMotionTarget::cleanClass();
131 SoScXMLNavigationTarget::cleanClass();
132
133 CC_MUTEX_DESTRUCT(PImpl::syncmutex);
134 PImpl::syncmutex = NULL;
135 }
136
137 void
syncLock(void)138 SoScXMLNavigation::syncLock(void)
139 {
140 CC_MUTEX_LOCK(PImpl::syncmutex);
141 }
142
143 void
syncUnlock(void)144 SoScXMLNavigation::syncUnlock(void)
145 {
146 CC_MUTEX_UNLOCK(PImpl::syncmutex);
147 }
148