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
00175 static SoDeviceContextSharedGroup* getSharedGroupFromId( SharedGroupId id );
00176
00177 private:
00178
00180 virtual ~SoDeviceContextSharedGroup();
00181
00186 void forceReleaseAttachedObject();
00187
00188 bool m_isDisposing;
00189
00190 private:
00191
00192 void commonConstructor();
00193
00194
00195
00196
00197 SoDeviceContext* getDeviceContextToBindForDelete() const;
00198
00199 SoDeviceContextSet m_ctxSet;
00200 int m_id;
00201 SoDeviceContextSharedGroup* m_mergedGroup;
00202
00204 typedef std::list<SoDeviceContextSharedGroup*> SoDeviceContexSharedGroupList;
00205 static SbThreadSpinlock s_sharedGroupListLock;
00206 static SoDeviceContexSharedGroupList s_sharedGroupList;
00207 static int s_sharedGroupId;
00208
00210 typedef std::list<SoBaseContextCache*> SoBaseContextCacheList;
00211 SoBaseContextCacheList m_listContextedObject;
00212 bool m_isClearingPendingList;
00213
00215 SoSharedGroupReferenceList m_intrusivelistContextedObject;
00216
00218 typedef std::set<SoBaseContextObject*> SoBaseContextObjectList;
00219 SoBaseContextObjectList m_waitingToBeFreed;
00220
00222 SbThreadId_t m_threadId;
00223
00230 mutable SbThreadMutex m_sharedGroupMembersMutex;
00231
00232
00233
00234
00235
00236 static int s_debuggingLevel;
00237
00239 SbEventHandler<SoDeviceContextSharedGroup*> m_destroyNotificationCallback;
00240 SbEventHandler<SoDeviceContextSharedGroup*> m_disposeNotificationCallback;
00241 };
00242
00243
00244 inline void SoDeviceContextSharedGroup::setDisposing( bool b )
00245 {
00246 m_isDisposing = b;
00247 }
00248
00249 inline SbThreadId_t SoDeviceContextSharedGroup::getThreadId() const
00250 {
00251 return m_threadId;
00252 }
00253
00254 #ifdef _MSC_VER
00255 #pragma warning( pop )
00256 #endif
00257
00258 #endif // SO_DEVICE_CONTEXT_SHARE_GROUP_H
00259
00260
00261