]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MONITOR/AliDimIntNotifier.cxx
Changed class inheritance (TObject->TTask) and fixed bug
[u/mrichter/AliRoot.git] / MONITOR / AliDimIntNotifier.cxx
1 // @(#)root/eve:$Id$
2 // Author: Matevz Tadel 2007
3
4 /**************************************************************************
5  * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6  * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
7  * full copyright notice.                                                 *
8  **************************************************************************/
9
10 #include "AliDimIntNotifier.h"
11 #include <TError.h>
12 #include <signal.h>
13
14 //______________________________________________________________________________
15 // Full description of AliDimIntNotifier
16 //
17
18 ClassImp(AliDimIntNotifier)
19
20 Long_t AliDimIntNotifier::fgMainThreadId = 0;
21
22 void AliDimIntNotifier::SetMainThreadId()
23 {
24   fgMainThreadId = TThread::SelfId();
25 }
26
27 AliDimIntNotifier::AliDimIntNotifier(const TString& service) :
28   DimUpdatedInfo(service, -1),
29   fReThreader(),
30   fNotifyLck(kTRUE),
31   fLastMessage(-1)
32 {
33   fReThreader.Connect("Timeout()", "AliDimIntNotifier", this, "DimMessage()");
34 }
35
36 void AliDimIntNotifier::StartTimer()
37 {
38   fReThreader.Reset();
39   fReThreader.TurnOn();
40   pthread_kill((pthread_t)fgMainThreadId, SIGALRM); 
41 }
42
43 void AliDimIntNotifier::StopTimer()
44 {
45   fReThreader.TurnOff();
46 }
47
48 void AliDimIntNotifier::infoHandler()
49 {
50   // Handle DIM message
51
52   fNotifyLck.Lock();
53   fLastMessage = getData() ? getInt() : -1;
54   if (TThread::SelfId() != fgMainThreadId)
55   {
56     StartTimer();
57   }
58   else
59   {
60     ::Warning("DIMinfoHandler", "DIM message received from CINT thread.");
61     DimMessage();
62   }
63   fNotifyLck.UnLock();
64 }
65
66 void AliDimIntNotifier::infoHandlerTest(Int_t fake)
67 {
68   // Fake handler for testing.
69
70   fNotifyLck.Lock();
71   fLastMessage = fake;
72   if (TThread::SelfId() != fgMainThreadId)
73   {
74     StartTimer();
75   }
76   else
77   {
78     Warning("infoHandlerTest", "Was called from CINT thread ...");
79     DimMessage();
80   }
81   fNotifyLck.UnLock();
82 }
83
84 void AliDimIntNotifier::DimMessage(Int_t)
85 {
86   StopTimer();
87   if (fLastMessage != -1)
88   {
89     Emit("DimMessage(Int_t)", fLastMessage);
90   }
91 }