Hi all

..I am trying to use threads but it is driving me crazy..

In another post here I found an example how to use member function with
osgthreads..

..it works fine if the function is in that class.. but if I try to give a
member function pointer nothig works anymore..

so here is my code :


#include <OpenSG/OSGBaseFunctions.h>
#include <OpenSG/OSGThread.h>
#include <OpenSG/OSGThreadManager.h>
#include <OpenSG/OSGLock.h>

OSG_BEGIN_NAMESPACE;
using namespace std;

template <typename T>
class MyThreadWrapper
{
    public:
        class MyThread : public Thread
        {
            private:

                T* caller;
                void (T::*fkt) (void);

                typedef Thread Inherited;
                MyThread(const MyThread &source);
                void operator =(const MyThread &source);

            protected:
                Lock *pLock;
                static MPThreadType _type;

                static Thread *create(const Char8  *szName, UInt32  uiId) {
                    return new MyThread(szName, uiId);
                }

                MyThread(const Char8 *szName, UInt32 uiId) :
Inherited(szName, uiId), pLock(NULL) {
                    //_type = new MPThreadType("MyThread", "Thread",
(CreateThreadF) MyThread::create, NULL);
                    fprintf(stderr, "Create Lock\n");
                    fflush(stderr);
                    pLock = ThreadManager::the()->getLock(NULL);
                }

                virtual ~MyThread(void){}

                void workProc(void) {
                    while(1) {
                        cout << "\ntest";
                        //(caller->*fkt)(void);
                        osgsleep(100);
                    }
                }

            public:

                UInt32 _uiThreadId;

                static MyThread* get (Char8* szName){
                    BaseThread *pThread =
ThreadManager::the()->getThread(szName, "MyThread");
                    return dynamic_cast<MyThread* >(pThread);
                }

                static MyThread *find(Char8 *szName) {
                    BaseThread *pThread =
ThreadManager::the()->findThread(szName);
                    return dynamic_cast<MyThread *>(pThread);
                }

                void setPipe (T* cl, void (T::*fktPt)(void)) {
                    caller = cl;
                    fkt = fktPt;
                }
        };
};

template <typename T>
MPThreadType MyThreadWrapper<T>::MyThread::_type("MyThread", "Thread",
(CreateThreadF) MyThread::create, NULL);
//MPThreadType MyThreadWrapper::MyThread::_type("MyThread", "Thread",
(CreateThreadF) MyThread::create, NULL);

class OSGPeriphery {
    private:

        MyThreadWrapper<OSGPeriphery>::MyThread* pThread;
        //MyThreadWrapper::MyThread* pThread;

    public:
       void startThread() {

          fprintf(stderr, "Derived Thread Test Started\n");
          pThread = MyThreadWrapper<OSGPeriphery>::MyThread::get("My1");
          //pThread = MyThreadWrapper::MyThread::get("My1");
          pThread->setPipe(this, &OSGPeriphery::update);

          if(pThread == NULL)
          {
            fprintf(stderr, "Could not create thread\n");
          }

          pThread->_uiThreadId = 1;
          pThread->run(1);
       }

      void update() {
             cout <<"\nbla";
       }
};

it works fine without the template crap and the setPipe fkt..

I get the following error : "could not find type named :: My1"

..I believe the problem is the MPThreadType.. but I have no idea what is
going on.. (first time I do something like this..)

I am gratefull for any help, thanks for your time,

Victor
------------------------------------------------------------------------------
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to