Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TMessage.h
Go to the documentation of this file.
1 // @(#)root/net:$Id$
2 // Author: Fons Rademakers 19/12/96
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TMessage
13 #define ROOT_TMessage
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TMessage //
19 // //
20 // Message buffer class used for serializing objects and sending them //
21 // over the network. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #include "Compression.h"
26 #include "TBufferFile.h"
27 #include "MessageTypes.h"
28 #include "TBits.h"
29 
30 class TList;
31 class TVirtualStreamerInfo;
32 
33 class TMessage : public TBufferFile {
34 
35 friend class TAuthenticate;
36 friend class TSocket;
37 friend class TUDPSocket;
38 friend class TPSocket;
39 friend class TXSocket;
40 
41 private:
42  TList *fInfos{nullptr}; // List of TStreamerInfo used in WriteObject
43  TBits fBitsPIDs; // Array of bits to mark the TProcessIDs uids written to the message
44  UInt_t fWhat{0}; // Message type
45  TClass *fClass{nullptr}; // If message is kMESS_OBJECT pointer to object's class
46  Int_t fCompress{0}; // Compression level and algorithm
47  char *fBufComp{nullptr}; // Compressed buffer
48  char *fBufCompCur{nullptr}; // Current position in compressed buffer
49  char *fCompPos{nullptr}; // Position of fBufCur when message was compressed
50  Bool_t fEvolution{kFALSE}; // True if support for schema evolution required
51 
52  static Bool_t fgEvolution; //True if global support for schema evolution required
53 
54  // TMessage objects cannot be copied or assigned
55  TMessage(const TMessage &); // not implemented
56  void operator=(const TMessage &); // not implemented
57 
58  // used by friend TSocket
59  Bool_t TestBitNumber(UInt_t bitnumber) const { return fBitsPIDs.TestBitNumber(bitnumber); }
60 
61 protected:
62  TMessage(void *buf, Int_t bufsize); // only called by T(P)Socket::Recv()
63  void SetLength() const; // only called by T(P)Socket::Send()
64 
65 public:
66  TMessage(UInt_t what = kMESS_ANY, Int_t bufsiz = TBuffer::kInitialSize);
67  virtual ~TMessage();
68 
69  void ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t force) override;
70  void Forward();
71  TClass *GetClass() const { return fClass;}
72  void TagStreamerInfo(TVirtualStreamerInfo* info) override;
73  void Reset() override;
74  void Reset(UInt_t what) { SetWhat(what); Reset(); }
75  UInt_t What() const { return fWhat; }
76  void SetWhat(UInt_t what);
77 
78  void EnableSchemaEvolution(Bool_t enable = kTRUE) { fEvolution = enable; }
79  Bool_t UsesSchemaEvolution() const { return fEvolution; }
80  TList *GetStreamerInfos() const { return fInfos; }
81  Int_t GetCompressionAlgorithm() const;
82  Int_t GetCompressionLevel() const;
83  Int_t GetCompressionSettings() const;
84  void SetCompressionAlgorithm(Int_t algorithm = ROOT::RCompressionSetting::EAlgorithm::kUseGlobal);
85  void SetCompressionLevel(Int_t level = ROOT::RCompressionSetting::ELevel::kUseMin);
86  void SetCompressionSettings(Int_t settings = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault);
87  Int_t Compress();
88  Int_t Uncompress();
89  char *CompBuffer() const { return fBufComp; }
90  Int_t CompLength() const { return (Int_t)(fBufCompCur - fBufComp); }
91  UShort_t WriteProcessID(TProcessID *pid) override;
92 
93  static void EnableSchemaEvolutionForAll(Bool_t enable = kTRUE);
94  static Bool_t UsesSchemaEvolutionForAll();
95 
96  ClassDefOverride(TMessage,0) // Message buffer class
97 };
98 
99 //______________________________________________________________________________
100 inline Int_t TMessage::GetCompressionAlgorithm() const
101 {
102  return (fCompress < 0) ? -1 : fCompress / 100;
103 }
104 
105 //______________________________________________________________________________
106 inline Int_t TMessage::GetCompressionLevel() const
107 {
108  return (fCompress < 0) ? -1 : fCompress % 100;
109 }
110 
111 //______________________________________________________________________________
112 inline Int_t TMessage::GetCompressionSettings() const
113 {
114  return (fCompress < 0) ? -1 : fCompress;
115 }
116 
117 #endif