v2.10-0 (21000JUN2005)

Go4TaskHandler
Class TGo4TaskHandler


class TGo4TaskHandler
derived from TNamed

This class is responsible for the interconnection of two tasks:
provided are three communication channels (data, command, status),
one thread runnable is acting on each transport channel (e.g. socket);
one queue (buffer) is assigned to each channel
depending on client or server mode of the task handler, the threads get objects
from transporl and put them into the queue, or vice versa. (servertask sends commands,
but receives data and status objects)
taskhander is named such that it can be found in a list (i.e. task manager) by the server task
which may serve more than one client tasks


Field Summary
 private Bool_tfbClientMode
          True if taskhandler runs in client mode
 private Bool_tfbIsAborting
          True if taskhandler is being aborted e.g. by remove exception
 private Bool_tfbMasterMode
          True if taskhandler runs in master mode (sends commands, receives data and status).
 const static const Text_t[]fgcCOMMANDTHREAD
          Suffix for command thread name
 const static const Text_t[]fgcCONNECT
          Initial string for connect request (raw transport)
 const static const Text_t[]fgcDATATHREAD
          Suffix for data thread name
 const static const Text_t[]fgcDISCONNECT
          Initial string for disconnect request (raw transport)
 const static const Text_t[]fgcERROR
          Error string for client connect negotiations (raw transport)
 const static const Text_t[]fgcMASTER
          Task identifier for client connect negotiations (raw transport)
 const static const Text_t[]fgcOK
          Ok string for client connect negotiations (raw transport)
 const static const Text_t[]fgcSLAVE
          Task identifier for client connect negotiations (raw transport)
 const static const Text_t[]fgcSTATUSTHREAD
          Suffix for status thread name
 const static const Int_tfgiPORTWAITCYCLES
          Cycles to wait for a nonzero portnumber
 const static const Int_tfgiTHREADSTOPCYCLES
          cycles to wait for taskhandler thread stop on disconnection
 const static const UInt_tfguCOMMANDQUEUESIZE
          Maximum entries allowed for command queue
 const static const UInt_tfguCONNECTORPORT
          Default port number of negotiation connection (raw transport)
 const static const UInt_tfguDATAQUEUESIZE
          Maximum entries allowed for data queue
 const static const UInt_tfguPORTWAITTIME
          Time for each waitgetport cycle
 const static const UInt_tfguSTATUSQUEUESIZE
          Maximum entries allowed for status queue
 const static const UInt_tfguTHREADSTOPTIME
          time for each threadstop wait cycle
 const static const UInt_tfguTRANSPORTCHECKDELAY
          Delay time (ms) to wait between two checks of transport connection
 private static TNamedfgxADMINISTRATORACCOUNT
          This keeps account for admin connection.
 private static TNamedfgxCONTROLLERACCOUNT
          This keeps account for controller connection.
 private static TNamedfgxOBSERVERACCOUNT
          This keeps account for observer connection.
 private Int_tfiComPort
          Command connection port number
 private Int_tfiDatPort
          Data connection port number
 private Go4CommandMode_tfiRole
          For server connection to client: This indicates role of
connected client, if client is master.
 private Int_tfiStatPort
          Status connection port number
 private UInt_tfuNegPort
          Actual port number of negotiation connection (raw transport)
 private TGo4Queue*fxCommandQueue
          Buffers (queues) for the three transport channels:
 private TGo4CommandRunnable*fxCommandRun
          link to command runnable which is managed by thread handler
 private TGo4Socket*fxCommandTransport
          Transport channels (e.g. sockets) for command, status, data
 private TStringfxComName
          Remember name of command thread
 private TGo4Queue*fxDataQueue
           
 private TGo4DataRunnable*fxDataRun
          link to data runnable which is managed by thread handler
 private TGo4Socket*fxDataTransport
           
 private TStringfxDatName
          Remember name of data thread
 private TStringfxHostName
          Remember name of remote task handler
 private TGo4CommandInvoker*fxInvoker
          Link to external command invoker instance used for direct command in client mode:
 private TStringfxStatName
          Remember name of status thread
 private TGo4Queue*fxStatusQueue
           
 private TGo4StatusRunnable*fxStatusRun
          link to status runnable which is managed by thread handler
 private TGo4Socket*fxStatusTransport
           
 private TGo4ThreadHandler*fxThreadHandler
          link to external threadhandler which is used for the transport service threads (runnables);
these runnables are instantiated from the task handler ctor and passed to the thread handler who takes
over the responsibility for the runnables (threadhandler internal mode threads)
 private TGo4ThreadManager*fxThreadManager
          Link to threadmanager that owns the task handler, used for runnable ctors

Fields inherited from class TNamed
fName, fTitle

Constructor Summary
 TGo4TaskHandler(const char * name, TGo4ThreadManager* threadmanager, Bool_t clientmode, Bool_t mastermode, UInt_t negotiationport)
           
 private TGo4TaskHandler()
           

Destructor Summary
 virtual synchronized ~TGo4TaskHandler()
           

Method Summary
 voidClearQueues()
          Clear all entries of queues.
 voidCloseChannels()
          Close transport channels and clear queues.
 Bool_tConnect(const char * host, TGo4Socket* negotiator)
          establishes the connections of all three transport channels and starts the service threads
 Bool_tConnectClientChannel(const char * name, TGo4Socket* negotiator, TGo4Socket* channel, const char * host)
          method defining the connection protocol of
one data transport channel (data, status, or command).
 Bool_tConnectServerChannel(const char * name, TGo4Socket* negotiator, TGo4Socket* channel, const char * host)
          Method defining the connection protocol of
one data transport channel (data, status, or command).
 virtual TGo4TaskHandlerStatus*CreateStatus()
          create a status object with information on the
current taskhandler state. this object may be sent to the
server or may be used to restore current status by
memento mechanism
 Bool_tDisConnect(Bool_t waitforclient)
          Closes the connections of all three transport channels.
 const TGo4Queue*GetCommandQueue()
           
 const TGo4Socket*GetCommandTransport()
           
 const const char *GetComName()
           
 const Int_tGetComPort()
           
 const TGo4Queue*GetDataQueue()
           
 const TGo4Socket*GetDataTransport()
           
 const const char *GetDatName()
           
 const Int_tGetDatPort()
           
 const const char *GetHostName()
           
 const TGo4CommandInvoker*GetInvoker()
          returns pointer to copy of client invoker which may be used
by server to check the valid command clients
 Go4CommandMode_tGetRole()
           
 const const char *GetStatName()
           
 const Int_tGetStatPort()
           
 const TGo4Queue*GetStatusQueue()
           
 const TGo4Socket*GetStatusTransport()
           
 const TGo4ThreadManager*GetThreadManager()
           
 const Bool_tIsAborting()
          Check whether this instance is currently being aborted
 const Bool_tIsClientMode()
          Check whether this instance is client or server taskhandler
 const Bool_tIsMasterMode()
          Check whether this instance is client or server taskhandler
 Bool_tServerLogin(TGo4Socket* connector, Go4CommandMode_t account)
          Negotiate login to requested server channel with account type
 TGo4Socket*ServerRequest(const char * host)
          request to server at host to connect or disconnect us, returns negotiation channel
 voidSetAborting(Bool_t isaborting)
          sets the internal aborting state of this taskhandler instance;
will be checked before an exception tries to cancel this taskhandler
 static voidSetAdminAccount(const char * name, const char * passwd)
          Specify login name and password for administrator account.
 static voidSetCtrlAccount(const char * name, const char * passwd)
          Specify login name and password for controller account.
 voidSetInvoker(TGo4CommandInvoker* inv)
          sets pointer to client invoker which may be used
by server to check the valid command clients
 voidSetNegotiationPort(UInt_t port)
          Set port for the negotiation channel (client mode).
 static voidSetObservAccount(const char * name, const char * passwd)
          Specify login name and password for observer account.
 voidSetRole(Go4CommandMode_t role)
           
 voidStartTransportThreads()
          Start all transport threads of this taskhandler (command,
data, status).
 Bool_tStopTransportThreads(Bool_t wait)
          Stop all transport threads of this taskhandler (command,
data, status).
 Int_tWaitGetPort(TGo4Socket* sock)
          Get actual local port number of specified
Go4 socket.
 Bool_tWaitThreadStop(const char * name)
          Wait for the thread of name to be stopped.

Methods inherited from class TNamed
operator=, Clear, Clone, Compare, Copy, FillBuffer, GetName, GetTitle, Hash, IsSortable, SetName, SetNameTitle, SetTitle, ls, Print, Sizeof, Class, Class_Name, Class_Version, Dictionary, IsA, ShowMembers, Streamer, StreamerNVirtual, DeclFileName, ImplFileLine, ImplFileName, DeclFileLine

Field Detail

fbClientMode

private Bool_t fbClientMode
True if taskhandler runs in client mode

fbIsAborting

private Bool_t fbIsAborting
True if taskhandler is being aborted e.g. by remove exception

fbMasterMode

private Bool_t fbMasterMode
True if taskhandler runs in master mode (sends commands, receives data and status). Otherwise false.

fgcCOMMANDTHREAD

public const static const Text_t[] fgcCOMMANDTHREAD
Suffix for command thread name

fgcCONNECT

public const static const Text_t[] fgcCONNECT
Initial string for connect request (raw transport)

fgcDATATHREAD

public const static const Text_t[] fgcDATATHREAD
Suffix for data thread name

fgcDISCONNECT

public const static const Text_t[] fgcDISCONNECT
Initial string for disconnect request (raw transport)

fgcERROR

public const static const Text_t[] fgcERROR
Error string for client connect negotiations (raw transport)

fgcMASTER

public const static const Text_t[] fgcMASTER
Task identifier for client connect negotiations (raw transport)

fgcOK

public const static const Text_t[] fgcOK
Ok string for client connect negotiations (raw transport)

fgcSLAVE

public const static const Text_t[] fgcSLAVE
Task identifier for client connect negotiations (raw transport)

fgcSTATUSTHREAD

public const static const Text_t[] fgcSTATUSTHREAD
Suffix for status thread name

fgiPORTWAITCYCLES

public const static const Int_t fgiPORTWAITCYCLES
Cycles to wait for a nonzero portnumber

fgiTHREADSTOPCYCLES

public const static const Int_t fgiTHREADSTOPCYCLES
cycles to wait for taskhandler thread stop on disconnection

fguCOMMANDQUEUESIZE

public const static const UInt_t fguCOMMANDQUEUESIZE
Maximum entries allowed for command queue

fguCONNECTORPORT

public const static const UInt_t fguCONNECTORPORT
Default port number of negotiation connection (raw transport)

fguDATAQUEUESIZE

public const static const UInt_t fguDATAQUEUESIZE
Maximum entries allowed for data queue

fguPORTWAITTIME

public const static const UInt_t fguPORTWAITTIME
Time for each waitgetport cycle

fguSTATUSQUEUESIZE

public const static const UInt_t fguSTATUSQUEUESIZE
Maximum entries allowed for status queue

fguTHREADSTOPTIME

public const static const UInt_t fguTHREADSTOPTIME
time for each threadstop wait cycle

fguTRANSPORTCHECKDELAY

public const static const UInt_t fguTRANSPORTCHECKDELAY
Delay time (ms) to wait between two checks of transport connection

fgxADMINISTRATORACCOUNT

private static TNamed fgxADMINISTRATORACCOUNT
This keeps account for admin connection.
Name is accountname, title is password. May be set from outside by
public methods SetObservAccount and SetObservPasswd.
Later we might keep this with encryption...

fgxCONTROLLERACCOUNT

private static TNamed fgxCONTROLLERACCOUNT
This keeps account for controller connection.
Name is accountname, title is password. May be set from outside by
public methods SetCtrlAccount and SetCtrlPasswd.
Later we might keep this with encryption...

fgxOBSERVERACCOUNT

private static TNamed fgxOBSERVERACCOUNT
This keeps account for observer connection.
Name is accountname, title is password. May be set from outside by
public methods SetObservAccount and SetObservPasswd.
Later we might keep this with encryption...

fiComPort

private Int_t fiComPort
Command connection port number

fiDatPort

private Int_t fiDatPort
Data connection port number

fiRole

private Go4CommandMode_t fiRole
For server connection to client: This indicates role of
connected client, if client is master. Depending on role,
some actions may be forbidden. Role is equivalent to
allowed command execution mode.

fiStatPort

private Int_t fiStatPort
Status connection port number

fuNegPort

private UInt_t fuNegPort
Actual port number of negotiation connection (raw transport)

fxCommandQueue

private TGo4Queue* fxCommandQueue
Buffers (queues) for the three transport channels:

fxCommandRun

private TGo4CommandRunnable* fxCommandRun
link to command runnable which is managed by thread handler
supplierCardinality 1
clientCardinality 1

fxCommandTransport

private TGo4Socket* fxCommandTransport
Transport channels (e.g. sockets) for command, status, data

fxComName

private TString fxComName
Remember name of command thread

fxDataQueue

private TGo4Queue* fxDataQueue

fxDataRun

private TGo4DataRunnable* fxDataRun
link to data runnable which is managed by thread handler
supplierCardinality 1
clientCardinality 1

fxDataTransport

private TGo4Socket* fxDataTransport

fxDatName

private TString fxDatName
Remember name of data thread

fxHostName

private TString fxHostName
Remember name of remote task handler

fxInvoker

private TGo4CommandInvoker* fxInvoker
Link to external command invoker instance used for direct command in client mode:

fxStatName

private TString fxStatName
Remember name of status thread

fxStatusQueue

private TGo4Queue* fxStatusQueue

fxStatusRun

private TGo4StatusRunnable* fxStatusRun
link to status runnable which is managed by thread handler
supplierCardinality 1
clientCardinality 1

fxStatusTransport

private TGo4Socket* fxStatusTransport

fxThreadHandler

private TGo4ThreadHandler* fxThreadHandler
link to external threadhandler which is used for the transport service threads (runnables);
these runnables are instantiated from the task handler ctor and passed to the thread handler who takes
over the responsibility for the runnables (threadhandler internal mode threads)
associates <{TGo4ThreadHandler}>

fxThreadManager

private TGo4ThreadManager* fxThreadManager
Link to threadmanager that owns the task handler, used for runnable ctors
Constructor Detail

TGo4TaskHandler

public TGo4TaskHandler(const char * name, TGo4ThreadManager* threadmanager, Bool_t clientmode, Bool_t mastermode, UInt_t negotiationport)

TGo4TaskHandler

private TGo4TaskHandler()
Method Detail

~TGo4TaskHandler

public virtual synchronized ~TGo4TaskHandler()
Method Detail

ClearQueues

public void ClearQueues()
Clear all entries of queues.

CloseChannels

public void CloseChannels()
Close transport channels and clear queues.

Connect

public Bool_t Connect(const char * host, TGo4Socket* negotiator)
establishes the connections of all three transport channels and starts the service threads

ConnectClientChannel

public Bool_t ConnectClientChannel(const char * name, TGo4Socket* negotiator, TGo4Socket* channel, const char * host)
method defining the connection protocol of
one data transport channel (data, status, or command).
For client socket mode (used by taskhandler)

ConnectServerChannel

public Bool_t ConnectServerChannel(const char * name, TGo4Socket* negotiator, TGo4Socket* channel, const char * host)
Method defining the connection protocol of
one data transport channel (data, status, or command).
For server socket mode (used by taskmanager)

CreateStatus

public virtual TGo4TaskHandlerStatus* CreateStatus()
create a status object with information on the
current taskhandler state. this object may be sent to the
server or may be used to restore current status by
memento mechanism

DisConnect

public Bool_t DisConnect(Bool_t waitforclient)
Closes the connections of all three transport channels.
Argument waitforclient specifies if server shall wait
for client handshake over negotiation channel
before shutting down the sockets.

GetCommandQueue

public const TGo4Queue* GetCommandQueue()

GetCommandTransport

public const TGo4Socket* GetCommandTransport()

GetComName

public const const char * GetComName()

GetComPort

public const Int_t GetComPort()

GetDataQueue

public const TGo4Queue* GetDataQueue()

GetDataTransport

public const TGo4Socket* GetDataTransport()

GetDatName

public const const char * GetDatName()

GetDatPort

public const Int_t GetDatPort()

GetHostName

public const const char * GetHostName()

GetInvoker

public const TGo4CommandInvoker* GetInvoker()
returns pointer to copy of client invoker which may be used
by server to check the valid command clients

GetRole

public Go4CommandMode_t GetRole()

GetStatName

public const const char * GetStatName()

GetStatPort

public const Int_t GetStatPort()

GetStatusQueue

public const TGo4Queue* GetStatusQueue()

GetStatusTransport

public const TGo4Socket* GetStatusTransport()

GetThreadManager

public const TGo4ThreadManager* GetThreadManager()

IsAborting

public const Bool_t IsAborting()
Check whether this instance is currently being aborted

IsClientMode

public const Bool_t IsClientMode()
Check whether this instance is client or server taskhandler

IsMasterMode

public const Bool_t IsMasterMode()
Check whether this instance is client or server taskhandler

ServerLogin

public Bool_t ServerLogin(TGo4Socket* connector, Go4CommandMode_t account)
Negotiate login to requested server channel with account type

ServerRequest

public TGo4Socket* ServerRequest(const char * host)
request to server at host to connect or disconnect us, returns negotiation channel

SetAborting

public void SetAborting(Bool_t isaborting)
sets the internal aborting state of this taskhandler instance;
will be checked before an exception tries to cancel this taskhandler

SetAdminAccount

public static void SetAdminAccount(const char * name, const char * passwd)
Specify login name and password for administrator account.
This is used when client requests for a server connection.
For multiple master clients at a slave server, there can be
only one controller, but many observers with restricted command
rights.

SetCtrlAccount

public static void SetCtrlAccount(const char * name, const char * passwd)
Specify login name and password for controller account.
This is used when client requests for a server connection.
For multiple master clients at a slave server, there can be
only one controller. Master server at slave client has always
controller role.

SetInvoker

public void SetInvoker(TGo4CommandInvoker* inv)
sets pointer to client invoker which may be used
by server to check the valid command clients

SetNegotiationPort

public void SetNegotiationPort(UInt_t port)
Set port for the negotiation channel (client mode). Required
if connection should be done on different port after taskhandler was
created.

SetObservAccount

public static void SetObservAccount(const char * name, const char * passwd)
Specify login name and password for observer account.
This is used when client requests for a server connection.
For multiple master clients at a slave server, there can be
only one controller, but many observers with restricted command
rights.

SetRole

public void SetRole(Go4CommandMode_t role)

StartTransportThreads

public void StartTransportThreads()
Start all transport threads of this taskhandler (command,
data, status).

StopTransportThreads

public Bool_t StopTransportThreads(Bool_t wait)
Stop all transport threads of this taskhandler (command,
data, status). If wait is true, wait until threads are really
stopped before return. If not all threads were stopped
within defined stoptime and waitcycles, return value is false.

WaitGetPort

public Int_t WaitGetPort(TGo4Socket* sock)
Get actual local port number of specified
Go4 socket. Method polls until the port number is
not zero, i.e. the created server socket has been bound
to that number. Used by the Connect protocol to
find out server port before sending it to the client.

WaitThreadStop

public Bool_t WaitThreadStop(const char * name)
Wait for the thread of name to be stopped. Returns
false if thread has not reached stopped state within
the defined stoptime and cycles.

Association Links

to Class TNamed

This keeps account for admin connection.
Name is accountname, title is password. May be set from outside by
public methods SetObservAccount and SetObservPasswd.
Later we might keep this with encryption...

to Class TNamed

This keeps account for observer connection.
Name is accountname, title is password. May be set from outside by
public methods SetObservAccount and SetObservPasswd.
Later we might keep this with encryption...

to Class TNamed

This keeps account for controller connection.
Name is accountname, title is password. May be set from outside by
public methods SetCtrlAccount and SetCtrlPasswd.
Later we might keep this with encryption...

to Class TGo4ThreadManager

Link to threadmanager that owns the task handler, used for runnable ctors

to Class TGo4ThreadHandler

link to external threadhandler which is used for the transport service threads (runnables);
these runnables are instantiated from the task handler ctor and passed to the thread handler who takes
over the responsibility for the runnables (threadhandler internal mode threads)

associates <{TGo4ThreadHandler}>

to Class TGo4CommandInvoker

Link to external command invoker instance used for direct command in client mode:

to Class TGo4Queue

Buffers (queues) for the three transport channels:

to Class TGo4Queue

to Class TGo4Queue

to Class TGo4Socket

Transport channels (e.g. sockets) for command, status, data

to Class TGo4Socket

to Class TGo4Socket

to Class Go4CommandMode_t

For server connection to client: This indicates role of
connected client, if client is master. Depending on role,
some actions may be forbidden. Role is equivalent to
allowed command execution mode.

to Class TGo4StatusRunnable

link to status runnable which is managed by thread handler

Client Cardinality 1
Supplier Cardinality 1

to Class TGo4DataRunnable

link to data runnable which is managed by thread handler

Client Cardinality 1
Supplier Cardinality 1

to Class TGo4CommandRunnable

link to command runnable which is managed by thread handler

Client Cardinality 1
Supplier Cardinality 1

J.Adamczewski, M.Al-Turany, D.Bertini, H.G.Essel, S.Linev

30-06-2005