1 package GSM::SMS::Transport;
\r
3 use vars qw( $VERSION );
\r
6 use GSM::SMS::Config;
\r
12 ##########################################################################
\r
15 my $class = ref($proto) || $proto;
\r
17 bless($self, $class);
\r
19 # process constructor parameters
\r
20 $self->{"__CONFIG_FILE__"} = shift;
\r
22 # initialize class parameters
\r
23 # anonymous array to transports
\r
24 $self->{"__TRANSPORTS__"} = [];
\r
27 unless ( $self->{"__CONFIG__"} = read_config( $self->{"__CONFIG_FILE__"} )) {
\r
28 croak("Could not load config file : " . $self->{"__CONFIG_FILE__"} . "!");
\r
31 # print Dumper $self->{'__CONFIG__'};
\r
33 # initialise transport
\r
34 my $ress = $self->_init( $self->{"__CONFIG__"} );
\r
42 ##########################################################################
\r
44 my ($self, $msisdn, $pdu) = @_;
\r
46 my $transport = $self->_route($msisdn);
\r
47 return $transport->send($msisdn, $pdu) if $transport;
\r
52 ##########################################################################
\r
57 foreach my $transporter ( @{$self->get_transports()} ) {
\r
58 if (!$transporter->receive(\$pdu)) {
\r
65 # Get an array containing the transports
\r
66 ##########################################################################
\r
67 sub get_transports {
\r
69 return $self->{"__TRANSPORTS__"};
\r
74 ##########################################################################
\r
78 foreach my $transport ( @{$self->{"__TRANSPORTS__"}} ) {
\r
79 $transport->close();
\r
83 ##########################################################################
\r
85 ##########################################################################
\r
88 # Give us the handle to the correct transport to use
\r
89 # Implements the routing.
\r
90 # Routing is now only done by the 'prefix' config parameter
\r
92 my ($self, $msisdn) = @_;
\r
94 # print "route... ";
\r
95 foreach my $transport ( @{$self->{"__TRANSPORTS__"}} ) {
\r
96 # print "--> $transport\n";
\r
97 if ( $transport->has_valid_route($msisdn) ) {
\r
98 # print "found ($transport)\n";
\r
107 # Create the actual transports and initialize them
\r
109 my ($self, $conf) = @_;
\r
111 # print Dumper $conf;
\r
113 foreach my $transport ( keys %$conf ) {
\r
114 next if $transport =~ /default/;
\r
116 #print "T: $transport ... ";
\r
118 # load transport class, using the preferences
\r
119 my $transport_config = get_config($conf, $transport);
\r
120 my $transport_type = $transport_config->{"type"};
\r
122 # print Dumper $transport_config;
\r
124 # print "starting up $transport_type..\n";
\r
126 my $transport_instance = eval(
\r
127 "use GSM::SMS::Transport::$transport_type; my \$n = GSM::SMS::Transport::$transport_type->new(\$transport_config); return \$n;"
\r
132 # print "use Tektonica::iSMS::Transport::$transport_type; my \$n = Tektonica::iSMS::Transport::$transport->new(\$transport_config); return \$n;";
\r
134 # If we didn't succeeded in loading the transport, there is
\r
135 # sometghing wrong. better bail out now and inform user,
\r
136 # otherwise he can get the impression all is fine, while not!
\r
137 return -1 unless $transport_instance;
\r
139 push( @{$self->{"__TRANSPORTS__"}}, $transport_instance );
\r
149 GSM::SMS::Transport
\r
153 This can be best seen as a factory for the transports defined in the GSM::SMS::Transport::* modules.
\r
154 When given a config file, it dynamically loads the transports defined in that config file, and initializes them.
\r
158 =head2 new( $configfile )
\r
160 Create a new transport layer with the settings as in the config file. Please look in the example config file for the transport specific configuration settings.
\r
162 =head2 send( $msisdn, $pdu )
\r
164 Send a PDU message to the the msisdn. The transport layer will choose a transport according to the regular expression defined in the config file. This regexp matches against the msisdn.
\r
166 =head2 $pdu = $t->receive()
\r
168 Receive a pdu message from the transport layer. Undef when no new message available.
\r
172 Shut down transport layer, calls the transport specific close method.
\r
177 Johan Van den Brande <johan@vandenbrande.com>
\r