C++ Based OPC UA Client/Server/PubSub SDK

Platform independent class for a worker thread. More...

#include <uathread.h>

Inherited by IOManagerUaNodePrivate, PubSubBase::PubSubNetworkBackendUdp, PubSubBase::PubSubResources, PubSubManagerPrivate, SamplingEngine [private], UaClientSdk::UaReverseEndpoint, UaClientSdk::UaSessionPrivate, UaJobThread, UaServer, and UaSubscriptionManager.

Public Member Functions

 UaThread ()
 Constructs a thread management object without starting the thread.
virtual ~UaThread ()
 Destroys the thread management object.
virtual void start ()
 Starts the thread managed by this object. More...
OpcUa_Boolean wait (OpcUa_UInt32 time=OpcUa_UInt32_Max)
 Waits for the termination of the thread. More...
OpcUa_Boolean running () const
 Returns the running state of the thread. More...
OpcUa_Boolean finished () const
 Returns the finished state of the thread. More...

Static Public Member Functions

static OpcUa_UInt32 currentThread ()
 Get thread ID of current thread. More...
static void sleep (OpcUa_UInt32 secs)
 Sleep for n seconds. More...
static void msleep (OpcUa_UInt32 msecs)
 Sleep for n milliseconds. More...
static void usleep (OpcUa_UInt32 usecs)
 Sleep for n microseconds. More...

Protected Member Functions

virtual void run ()=0
 Main function of the thread. More...

Detailed Description

Platform independent class for a worker thread.

A UaThreads represents a separate thread of control within the program; it shares data with all the other threads within the process but executes independently in the way that a separate program does on a multitasking operating system. Instead of starting in main(), UaThreads begin executing in run().

A class representing a worker thread or a class that needs a background processing thread must be derived from UaThread and the method run() must be implemented as main function for the thread in this class. See the following sample code for the definition of such a class and the use of the class.

class MyWorkerThread : public UaThread
virtual ~MyWorkerThread(){}
void run()
// Do something here
// Use worker thread
MyWorkerThread myThread;
// Start worker thread
// Wait for completion

The class is also used by the UaThreadPool. If you have recurring task you want to execute in worker threads it is more efficient to use UaThread

It is not possible to create shallow copies of this Class.

Member Function Documentation

OpcUa_UInt32 UaThread::currentThread ( )

Get thread ID of current thread.

the thread ID of current thread.
OpcUa_Boolean UaThread::finished ( ) const

Returns the finished state of the thread.

OpcUa_True if finished OpcUa_False if not.
void UaThread::msleep ( OpcUa_UInt32  msecs)

Sleep for n milliseconds.

msecsthe milliseconds to sleep
virtual void UaThread::run ( )
protectedpure virtual

Main function of the thread.

Must be implemented by the derived class to execute the functionality

Implemented in UaSubscriptionManager, and PubSubBase::PubSubResources.

OpcUa_Boolean UaThread::running ( ) const

Returns the running state of the thread.

OpcUa_True if running OpcUa_False if not.
void UaThread::sleep ( OpcUa_UInt32  secs)

Sleep for n seconds.

secsthe seconds to sleep.
void UaThread::start ( )

Starts the thread managed by this object.

This starts a worker thread. This worker thread calls the method run wich is the main method of the worker thread. The method UaThread::run must be implemented by the class derived from UaThread. If the method run() returns, the worker thread ends

void UaThread::usleep ( OpcUa_UInt32  usecs)

Sleep for n microseconds.

usecsthe microseconds to sleep
OpcUa_Boolean UaThread::wait ( OpcUa_UInt32  time = OpcUa_UInt32_Max)

Waits for the termination of the thread.

timethe time when to shut down.
true if the thread is still running false if the thread is not longer running.

The documentation for this class was generated from the following files: