00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined SO_DEVICE_CONTEXT_SHARE_GROUP_H
00025 #define SO_DEVICE_CONTEXT_SHARE_GROUP_H
00026
00027 #include <Inventor/misc/SoRefCounter.h>
00028 #include <Inventor/STL/set>
00029 #include <Inventor/threads/SbThreadMutex.h>
00030 #include <Inventor/devices/SoSharedGroupReferenceList.h>
00031 #include <Inventor/SbEventHandler.h>
00032
00033 class SoDeviceContext;
00034 class SoBaseContextCache;
00035 class SoBaseContextObject;
00036
00037 #ifdef _MSC_VER
00038 #pragma warning( push )
00039 #pragma warning(disable:4251)
00040 #endif
00041
00052 class SoDeviceContextSharedGroup : public SoRefCounter
00053 {
00054 public:
00056 typedef std::set<SoDeviceContext*> SoDeviceContextSet;
00057
00059 SoDeviceContextSharedGroup();
00060
00062 SoDeviceContextSharedGroup(int id);
00063
00065 void add(SoDeviceContext* ctx);
00066
00068 void remove(SoDeviceContext* ctx);
00069
00071 void setId( int id );
00072
00074 int getId() const;
00075
00077 const SoDeviceContextSet& getContexts() const;
00078
00080 SoDeviceContext* getPrimaryContext() const;
00081
00083 bool contains(const SoDeviceContext* ctx) const;
00084
00090 void ref(SoBaseContextCache* object = NULL);
00091
00102 void unref(SoBaseContextCache* object = NULL);
00103
00104
00108 bool contains(SoBaseContextCache* object) const;
00109
00114 virtual void dispose();
00115
00116 private:
00117 typedef int SharedGroupId;
00118
00120 void setDisposeCallback(void (*f)(SoDeviceContextSharedGroup*));
00121
00123 void setDestroyNotificationCallback(void (*f)(SoDeviceContextSharedGroup*));
00124
00125 void setTargetMergedGroup(SoDeviceContextSharedGroup* sharedGroup);
00126
00130 void addToPendingDeleteList(SoBaseContextObject *obj);
00131
00135 static void checkRefIssues(SoBaseContextObject* object);
00136 static void checkRefIssues(SoBaseContextCache* cache);
00137
00139 void clearPendingDeleteList();
00140
00141 void setDisposing( bool b );
00142
00144 SbThreadId_t getThreadId() const;
00145
00147 static int getNewSharedIdGroup();
00148
00150 static void printSharedGroups();
00151
00155 bool hasValidContext() const;
00156
00158 SoDeviceContext* getPrimaryValidContext() const;
00159
00160
00161 static int getDebuggingLevel()
00162 { return s_debuggingLevel; }
00163
00165 inline static int getFallbackContextGlobalSharedId()
00166 {
00167 return -2;
00168 }
00169
00170 private:
00171
00173 virtual ~SoDeviceContextSharedGroup();
00174
00179 void forceReleaseAttachedObject();
00180
00181 bool m_isDisposing;
00182
00183 private:
00184
00185 void commonConstructor();
00186
00187
00188
00189
00190 SoDeviceContext* getDeviceContextToBindForDelete() const;
00191
00192 SoDeviceContextSet m_ctxSet;
00193 int m_id;
00194 SoDeviceContextSharedGroup* m_mergedGroup;
00195
00197 typedef std::list<SoDeviceContextSharedGroup*> SoDeviceContexSharedGroupList;
00198 static SbThreadSpinlock s_sharedGroupListLock;
00199 static SoDeviceContexSharedGroupList s_sharedGroupList;
00200 static int s_sharedGroupId;
00201
00203 typedef std::list<SoBaseContextCache*> SoBaseContextCacheList;
00204 SoBaseContextCacheList m_listContextedObject;
00205 bool m_isClearingPendingList;
00206
00208 SoSharedGroupReferenceList m_intrusivelistContextedObject;
00209
00211 typedef std::set<SoBaseContextObject*> SoBaseContextObjectList;
00212 SoBaseContextObjectList m_waitingToBeFreed;
00213
00215 SbThreadId_t m_threadId;
00216
00223 mutable SbThreadMutex m_sharedGroupMembersMutex;
00224
00225
00226
00227
00228
00229 static int s_debuggingLevel;
00230
00232 SbEventHandler<SoDeviceContextSharedGroup*> m_destroyNotificationCallback;
00233 SbEventHandler<SoDeviceContextSharedGroup*> m_disposeNotificationCallback;
00234 };
00235
00236
00237 inline void SoDeviceContextSharedGroup::setDisposing( bool b )
00238 {
00239 m_isDisposing = b;
00240 }
00241
00242 inline SbThreadId_t SoDeviceContextSharedGroup::getThreadId() const
00243 {
00244 return m_threadId;
00245 }
00246
00247 #ifdef _MSC_VER
00248 #pragma warning( pop )
00249 #endif
00250
00251 #endif // SO_DEVICE_CONTEXT_SHARE_GROUP_H
00252
00253
00254