blob: e28f98bc21a5dcc9c892cc21af757cac6b69c54c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#include "tao/Compression/Compression_Manager.h"
#include "tao/ORB_Constants.h"
TAO_BEGIN_VERSIONED_NAMESPACE_DECL
namespace TAO
{
CompressionManager::~CompressionManager ()
{
// Require to guard the deletion of the list
ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->mutex_);
this->factories_.length (0u);
}
void
CompressionManager::register_factory (::Compression::CompressorFactory_ptr
compressor_factory)
{
if (!::CORBA::is_nil (compressor_factory))
{
ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->mutex_);
CORBA::ULong const length = this->factories_.length ();
for (CORBA::ULong i = 0u; i < length; ++i)
{
::Compression::CompressorId const current =
this->factories_[i]->compressor_id ();
if (compressor_factory->compressor_id () == current)
{
throw ::Compression::FactoryAlreadyRegistered ();
}
}
factories_.length (length + 1u);
factories_[length] = ::Compression::CompressorFactory::_duplicate (
compressor_factory);
}
else
{
// @todo Standardize this minor code
throw ::CORBA::BAD_PARAM (CORBA::OMGVMCID | 44, CORBA::COMPLETED_NO);
}
}
void
CompressionManager::unregister_factory (::Compression::CompressorId
compressor_id)
{
ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->mutex_);
CORBA::ULong const length = this->factories_.length ();
for (CORBA::ULong i = 0u; i < length; ++i)
{
::Compression::CompressorId const current =
this->factories_[i]->compressor_id ();
if (current == compressor_id)
{
// Shuffle down the remainder
while (i < length-1u)
{
this->factories_[i] = this->factories_[i+1u];
++i;
}
this->factories_.length (length - 1u);
return;
}
}
// todo exception
throw ::Compression::UnknownCompressorId ();
}
::Compression::CompressorFactory_ptr
CompressionManager::get_factory (::Compression::CompressorId compressor_id)
{
ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->mutex_,
::Compression::CompressorFactory::_nil ());
CORBA::ULong const length = this->factories_.length ();
for (CORBA::ULong i = 0u; i < length; ++i)
{
::Compression::CompressorId const current =
this->factories_[i]->compressor_id ();
if (current == compressor_id)
{
return ::Compression::CompressorFactory::_duplicate (
this->factories_[i]);
}
}
throw ::Compression::UnknownCompressorId ();
}
::Compression::Compressor_ptr
CompressionManager::get_compressor (::Compression::CompressorId
compressor_id,
::Compression::CompressionLevel
compression_level)
{
::Compression::CompressorFactory_var factory = this->get_factory (
compressor_id);
return factory->get_compressor (compression_level);
}
::Compression::CompressorFactorySeq *
CompressionManager::get_factories ()
{
// todo
return 0;
}
}
TAO_END_VERSIONED_NAMESPACE_DECL
|