| 1 | package Asterisk::Store::Queue; | ||
| 2 | |||
| 3 | 1 | ▶ | use 5.008008; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use attributes; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 0 | ▶ | use Log::Log4perl qw( get_logger :levels ); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | |||
| 9 | |||
| 10 | require Exporter; | ||
| 11 | |||
| 12 | our @ISA = qw(Exporter); | ||
| 13 | |||
| 14 | # Items to export into callers namespace by default. Note: do not export | ||
| 15 | # names by default without a very good reason. Use EXPORT_OK instead. | ||
| 16 | # Do not simply export all your public functions/methods/constants. | ||
| 17 | |||
| 18 | # This allows declaration use Asterisk::Store::Queue ':all'; | ||
| 19 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||
| 20 | # will save memory. | ||
| 21 | our %EXPORT_TAGS = ( 'all' => [ qw( | ||
| 22 | |||
| 23 | ) ] ); | ||
| 24 | |||
| 25 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | ||
| 26 | |||
| 27 | our @EXPORT = qw( | ||
| 28 | |||
| 29 | ); | ||
| 30 | |||
| 31 | our $VERSION = '0.01'; | ||
| 32 | |||
| 33 | # global varibles | ||
| 34 | use vars qw( @global_entries $connection ); | ||
| 35 | |||
| 36 | # logger setup | ||
| 37 | my $root_logger = get_logger("Asterisk"); | ||
| 38 | my $base_logger = get_logger("Asterisk::Store::Queue"); | ||
| 39 | $base_logger->level($WARN); | ||
| 40 | $root_logger->level($ERROR); | ||
| 41 | my $layout = Log::Log4perl::Layout::PatternLayout->new( | ||
| 42 | "%d{ISO8601} %p %c %F:%-4L -- %m%n" | ||
| 43 | ); | ||
| 44 | my $file_appender = Log::Log4perl::Appender->new( | ||
| 45 | "Log::Dispatch::File", | ||
| 46 | filename => "log/queue.log", | ||
| 47 | mode => "append", | ||
| 48 | ); | ||
| 49 | my $screen_appender = Log::Log4perl::Appender->new( | ||
| 50 | "Log::Dispatch::Screen", | ||
| 51 | ); | ||
| 52 | $screen_appender->threshold($ERROR); | ||
| 53 | $file_appender->layout($layout); | ||
| 54 | $screen_appender->layout($layout); | ||
| 55 | $base_logger->add_appender($file_appender); | ||
| 56 | $root_logger->add_appender($screen_appender); | ||
| 57 | |||
| 58 | |||
| 59 | =head1 NAME | ||
| 60 | |||
| 61 | Asterisk::Store::Queue - Class for Asterisk queue objects | ||
| 62 | |||
| 63 | =head1 SYNOPSIS | ||
| 64 | |||
| 65 | use Asterisk::Store::Queue; | ||
| 66 | |||
| 67 | my $queueobj = Asterisk::Store::Queue->new( | ||
| 68 | queue => 'mainqueue', | ||
| 69 | max => 0, | ||
| 70 | calls => 0, | ||
| 71 | abandoned => 0, | ||
| 72 | holdtime => 0, | ||
| 73 | completed => 0, | ||
| 74 | servicelevel => 0, | ||
| 75 | servicelevelperf => 0, | ||
| 76 | weight => 0, | ||
| 77 | ); | ||
| 78 | |||
| 79 | ... | ||
| 80 | |||
| 81 | =head1 DESCRIPTION | ||
| 82 | |||
| 83 | This module is used to store queue objects such as those returned | ||
| 84 | from the Asterisk Manager Interface API. | ||
| 85 | |||
| 86 | =cut | ||
| 87 | |||
| 88 | # constructor method | ||
| 89 | sub new { | ||
| 90 | my $invoker = shift; | ||
| 91 | my $class = ref($invoker) || $invoker; | ||
| 92 | my $self = { | ||
| 93 | # attributes go here | ||
| 94 | queue => 'mainqueue', | ||
| 95 | max => 0, | ||
| 96 | calls => 0, | ||
| 97 | abandoned => 0, | ||
| 98 | holdtime => 0, | ||
| 99 | completed => 0, | ||
| 100 | servicelevel => 0, | ||
| 101 | servicelevelperf => 0, | ||
| 102 | weight => 0, | ||
| 103 | members => [], # array of Queue::Member objects | ||
| 104 | DEBUG => 0, | ||
| 105 | @_, # override attributes | ||
| 106 | }; | ||
| 107 | bless $self, $class; | ||
| 108 | if ($self->{'DEBUG'}) { | ||
| 109 | $base_logger->level($DEBUG); | ||
| 110 | }; | ||
| 111 | $base_logger->debug("creating Asterisk::Store::Queue object"); | ||
| 112 | return $self; | ||
| 113 | } | ||
| 114 | |||
| 115 | =head1 ATTRIBUTES | ||
| 116 | |||
| 117 | Base attrubutes, can be extended | ||
| 118 | |||
| 119 | =head2 queue | ||
| 120 | |||
| 121 | Queue name | ||
| 122 | |||
| 123 | =cut | ||
| 124 | sub queue { | ||
| 125 | my $self = shift; | ||
| 126 | if (@_) { | ||
| 127 | $self->{'queue'}= shift; | ||
| 128 | } | ||
| 129 | return $self->{'queue'}; | ||
| 130 | } | ||
| 131 | |||
| 132 | =head2 max | ||
| 133 | |||
| 134 | Max number of calls | ||
| 135 | |||
| 136 | =cut | ||
| 137 | sub max { | ||
| 138 | my $self = shift; | ||
| 139 | if (@_) { | ||
| 140 | $self->{'max'}= shift; | ||
| 141 | } | ||
| 142 | return $self->{'max'}; | ||
| 143 | } | ||
| 144 | |||
| 145 | =head2 calls | ||
| 146 | |||
| 147 | Number of current calls waiting in queue | ||
| 148 | |||
| 149 | =cut | ||
| 150 | sub calls { | ||
| 151 | my $self = shift; | ||
| 152 | if (@_) { | ||
| 153 | $self->{'calls'}= shift; | ||
| 154 | } | ||
| 155 | return $self->{'calls'}; | ||
| 156 | } | ||
| 157 | |||
| 158 | =head2 abandoned | ||
| 159 | |||
| 160 | Number of abandoed calls in queue | ||
| 161 | |||
| 162 | =cut | ||
| 163 | sub abandoned { | ||
| 164 | my $self = shift; | ||
| 165 | if (@_) { | ||
| 166 | $self->{'abandoned'}= shift; | ||
| 167 | } | ||
| 168 | return $self->{'abandoned'}; | ||
| 169 | } | ||
| 170 | |||
| 171 | =head2 holdtime | ||
| 172 | |||
| 173 | Current hold time for queue | ||
| 174 | |||
| 175 | =cut | ||
| 176 | sub holdtime { | ||
| 177 | my $self = shift; | ||
| 178 | if (@_) { | ||
| 179 | $self->{'holdtime'}= shift; | ||
| 180 | } | ||
| 181 | return $self->{'holdtime'}; | ||
| 182 | } | ||
| 183 | |||
| 184 | =head2 completed | ||
| 185 | |||
| 186 | Number of calls that have been completed in the queue | ||
| 187 | |||
| 188 | =cut | ||
| 189 | sub completed { | ||
| 190 | my $self = shift; | ||
| 191 | if (@_) { | ||
| 192 | $self->{'completed'}= shift; | ||
| 193 | } | ||
| 194 | return $self->{'completed'}; | ||
| 195 | } | ||
| 196 | |||
| 197 | =head2 servicelevel | ||
| 198 | |||
| 199 | Current service level | ||
| 200 | |||
| 201 | =cut | ||
| 202 | sub servicelevel { | ||
| 203 | my $self = shift; | ||
| 204 | if (@_) { | ||
| 205 | $self->{'servicelevel'}= shift; | ||
| 206 | } | ||
| 207 | return $self->{'servicelevel'}; | ||
| 208 | } | ||
| 209 | |||
| 210 | =head2 servicelevelperf | ||
| 211 | |||
| 212 | Service level performance | ||
| 213 | |||
| 214 | =cut | ||
| 215 | sub servicelevelperf { | ||
| 216 | my $self = shift; | ||
| 217 | if (@_) { | ||
| 218 | $self->{'servicelevelperf'}= shift; | ||
| 219 | } | ||
| 220 | return $self->{'servicelevelperf'}; | ||
| 221 | } | ||
| 222 | |||
| 223 | =head2 weight | ||
| 224 | |||
| 225 | Queue weight | ||
| 226 | |||
| 227 | =cut | ||
| 228 | sub weight { | ||
| 229 | my $self = shift; | ||
| 230 | if (@_) { | ||
| 231 | $self->{'weight'}= shift; | ||
| 232 | } | ||
| 233 | return $self->{'weight'}; | ||
| 234 | } | ||
| 235 | |||
| 236 | =head2 members | ||
| 237 | |||
| 238 | Queue members -- An array of Asterisk::Store::Queue::Member objects | ||
| 239 | |||
| 240 | =cut | ||
| 241 | sub members { | ||
| 242 | my $self = shift; | ||
| 243 | if (@_) { | ||
| 244 | $self->{'members'}= shift; | ||
| 245 | } | ||
| 246 | return $self->{'members'}; | ||
| 247 | } | ||
| 248 | |||
| 249 | =head2 DEBUG *bool* | ||
| 250 | |||
| 251 | Enable debugging by setting bool to true. | ||
| 252 | |||
| 253 | =cut | ||
| 254 | |||
| 255 | sub DEBUG { | ||
| 256 | my $self = shift; | ||
| 257 | if (@_) { | ||
| 258 | $self->{'DEBUG'}= shift; | ||
| 259 | } | ||
| 260 | if ($self->{'DEBUG'}) { | ||
| 261 | $base_logger->level($DEBUG); | ||
| 262 | }; | ||
| 263 | return $self->{'DEBUG'}; | ||
| 264 | } | ||
| 265 | |||
| 266 | =head1 PUBLIC METHODS | ||
| 267 | |||
| 268 | These are the publicly accesable methods | ||
| 269 | |||
| 270 | =cut | ||
| 271 | |||
| 272 | =head2 add_member() | ||
| 273 | |||
| 274 | Add a new member object to the queue. Must be a Asterisk::Queue::Member object | ||
| 275 | |||
| 276 | usage: | ||
| 277 | $queueobj->add_member($memberobj) | ||
| 278 | |||
| 279 | =cut | ||
| 280 | sub add_member() { | ||
| 281 | my $self = shift; | ||
| 282 | my $internalobj = shift; | ||
| 283 | if ( UNIVERSAL::isa $internalobj, 'Asterisk::Store::Queue::Member' ) { | ||
| 284 | push @{$self->{'members'}}, $internalobj; | ||
| 285 | } else { | ||
| 286 | $base_logger->warn("add_member failed: not a Asterisk::Store::Queue::Member object"); | ||
| 287 | return undef; | ||
| 288 | } | ||
| 289 | } | ||
| 290 | |||
| 291 | |||
| 292 | =head1 PRIVATE METHODS | ||
| 293 | |||
| 294 | These methods should not be accessed directly. | ||
| 295 | |||
| 296 | =cut | ||
| 297 | |||
| 298 | |||
| 299 | =head1 SEE ALSO | ||
| 300 | |||
| 301 | To be used with: | ||
| 302 | L<Asterisk::Store::Queue::Member> | ||
| 303 | L<Asterisk::Manager> | ||
| 304 | |||
| 305 | =head1 AUTHOR | ||
| 306 | |||
| 307 | Derek Carter, E<lt>goozbach@neverblock.com<gt> | ||
| 308 | |||
| 309 | =head1 COPYRIGHT AND LICENSE | ||
| 310 | |||
| 311 | Copyright (C) 2007 by Derek Carter | ||
| 312 | |||
| 313 | This library is free software; you can redistribute it and/or modify | ||
| 314 | it under the same terms as Perl itself, either Perl version 5.8.8 or, | ||
| 315 | at your option, any later version of Perl 5 you may have available. | ||
| 316 | |||
| 317 | |||
| 318 | =cut | ||
| 319 | |||
| 320 | 1; | ||