| 1 | package Net::Radio::oFono::NetworkRegistration; | ||
| 2 | |||
| 3 | use 5.010; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | Net::Radio::oFono::NetworkRegistration - provide NetworkRegistration interface for Modem objects | ||
| 10 | |||
| 11 | =cut | ||
| 12 | |||
| 13 | our $VERSION = '0.001'; | ||
| 14 | |||
| 15 | use Net::DBus qw(:typing); | ||
| 16 | |||
| 17 | require Net::Radio::oFono::NetworkOperator; | ||
| 18 | |||
| 19 | use Net::Radio::oFono::Roles::Manager qw(Operator NetworkOperator); | ||
| 20 | use base qw(Net::Radio::oFono::Modem Net::Radio::oFono::Roles::Manager); | ||
| 21 | |||
| 22 | =head1 SYNOPSIS | ||
| 23 | |||
| 24 | my $oFono = Net::Location::oFono->new(); | ||
| 25 | my @modems = Net::Location::oFono->get_modems(); | ||
| 26 | # show default network information | ||
| 27 | foreach my $modem_path (@modems) { | ||
| 28 | my $netreg = Net::Location::oFono->get_modem_interface($modem_path, "NetworkRegistration"); | ||
| 29 | say "Status: ", $netreg->GetProperty("Status"), | ||
| 30 | "Name: ", $netreg->GetProperty("Name"), | ||
| 31 | "LocationAreaCode: ", $netreg->GetProperty("LocationAreaCode"), | ||
| 32 | "CellId: ", $netreg->GetProperty("CellId"), | ||
| 33 | "Technology: ", $netreg->GetProperty("Technology"), | ||
| 34 | "MobileCountryCode: ", $netreg->GetProperty("MobileCountryCode"), | ||
| 35 | "MobileNetworkCode: ", $netreg->GetProperty("MobileNetworkCode"); | ||
| 36 | } | ||
| 37 | |||
| 38 | # show each available network | ||
| 39 | foreach my $modem_path (@modems) { | ||
| 40 | my $netreg = Net::Location::oFono->get_modem_interface($modem_path, "NetworkRegistration"); | ||
| 41 | my %operators = $netreg->GetOperators(); | ||
| 42 | foreach my $oper_path (keys %operators) { | ||
| 43 | my $oper = $netreg->GetOperator($oper_path); | ||
| 44 | say "Status: ", $oper->GetProperty("Status"), | ||
| 45 | "Name: ", $oper->GetProperty("Name"), | ||
| 46 | "MobileCountryCode: ", $oper->GetProperty("MobileCountryCode"), | ||
| 47 | "MobileNetworkCode: ", $oper->GetProperty("MobileNetworkCode"), | ||
| 48 | "Technologies: ", join("/", $oper->GetProperty("Technologies")); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | =head1 INHERITANCE | ||
| 53 | |||
| 54 | Net::Radio::oFono::NetworkRegistration | ||
| 55 | ISA Net::Radio::oFono::Modem | ||
| 56 | ISA Net::Radio::oFono::Helpers::EventMgr | ||
| 57 | DOES Net::Radio::oFono::Roles::RemoteObj | ||
| 58 | DOES Net::Radio::oFono::Roles::Manager | ||
| 59 | |||
| 60 | =head1 METHODS | ||
| 61 | |||
| 62 | See C<ofono/doc/network-api.txt> for valid properties and detailed | ||
| 63 | action description and possible errors. | ||
| 64 | |||
| 65 | =head2 _init($obj_path) | ||
| 66 | |||
| 67 | =cut | ||
| 68 | |||
| 69 | sub _init | ||
| 70 | { | ||
| 71 | my ( $self, $obj_path ) = @_; | ||
| 72 | |||
| 73 | ( my $interface = ref($self) ) =~ s/Net::Radio::oFono:://; | ||
| 74 | |||
| 75 | # initialize base class | ||
| 76 | $self->Net::Radio::oFono::Modem::_init($obj_path); | ||
| 77 | # initialize role | ||
| 78 | $self->Net::Radio::oFono::Roles::Manager::_init(); | ||
| 79 | |||
| 80 | return; | ||
| 81 | } | ||
| 82 | |||
| 83 | sub DESTROY | ||
| 84 | { | ||
| 85 | my $self = $_[0]; | ||
| 86 | |||
| 87 | # destroy role | ||
| 88 | $self->Net::Radio::oFono::Roles::Manager::DESTROY(); | ||
| 89 | # initialize base class | ||
| 90 | $self->Net::Radio::oFono::Modem::DESTROY(); | ||
| 91 | |||
| 92 | return; | ||
| 93 | } | ||
| 94 | |||
| 95 | =head2 GetOperators(;$force) | ||
| 96 | |||
| 97 | Retrieve array of operator object and properties. | ||
| 98 | |||
| 99 | This method can be used to retrieve the current operator list. This is | ||
| 100 | either an empty list (when not registered to any network) or a list with | ||
| 101 | one or more operators (when registered). | ||
| 102 | |||
| 103 | This list will also return (by oFono) cached values of previously seen | ||
| 104 | networks. Manual updates to list can only be done via the I<Scan()> method | ||
| 105 | call. | ||
| 106 | |||
| 107 | Set the I<$force> parameter to a true value when no D-Bus main loop | ||
| 108 | is running and signal handling might be incomplete. | ||
| 109 | |||
| 110 | Returns a hash with object paths of the operators as key and their | ||
| 111 | current properties as hash reference as value. | ||
| 112 | |||
| 113 | This method is injected by L<Net::Radio::oFono::Roles::Manager> as an alias | ||
| 114 | for L<Net::Radio::oFono::Roles::Manager/GetObjects(;$force)|GetObjects()>. | ||
| 115 | |||
| 116 | =head2 GetOperator($obj_path;$force) | ||
| 117 | |||
| 118 | Returns an instance of the specified L<Net::Radio::oFono::NetworkOperator|Operator>. | ||
| 119 | |||
| 120 | Set the I<$force> parameter to a true value when no D-Bus main loop | ||
| 121 | is running and signal handling might be incomplete. | ||
| 122 | |||
| 123 | This method is injected by L<Net::Radio::oFono::Roles::Manager> as an alias | ||
| 124 | for L<Net::Radio::oFono::Roles::Manager/GetObject($object_path;$force)|GetObject()>. | ||
| 125 | |||
| 126 | =head2 Register() | ||
| 127 | |||
| 128 | Attempts to register to the default network. The default network is | ||
| 129 | normally selected by the settings from the SIM card. | ||
| 130 | |||
| 131 | To register into another network, invoke I<Register()> on a | ||
| 132 | L<Net::Radio::oFono::NetworkOperator> instance returned via | ||
| 133 | I<GetOperators()>. | ||
| 134 | |||
| 135 | =cut | ||
| 136 | |||
| 137 | sub Register | ||
| 138 | { | ||
| 139 | my ($self) = @_; | ||
| 140 | |||
| 141 | $self->{remote_obj}->Register(); | ||
| 142 | |||
| 143 | return; | ||
| 144 | } | ||
| 145 | |||
| 146 | =head2 Scan() | ||
| 147 | |||
| 148 | Runs a network operator scan to discover the currently available operators. | ||
| 149 | This operation can take several seconds, and up to several minutes on some | ||
| 150 | modems. This can be used to help the user determine what is the best | ||
| 151 | operator to use if forced to roam on a foreign network. | ||
| 152 | |||
| 153 | =cut | ||
| 154 | |||
| 155 | sub Scan | ||
| 156 | { | ||
| 157 | my ($self) = @_; | ||
| 158 | |||
| 159 | return $self->{remote_obj}->Scan(); | ||
| 160 | } | ||
| 161 | |||
| 162 | =head1 BUGS | ||
| 163 | |||
| 164 | Please report any bugs or feature requests to C<bug-net-radio-ofono at rt.cpan.org>, or through | ||
| 165 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Radio-oFono>. I will be notified, and then you'll | ||
| 166 | automatically be notified of progress on your bug as I make changes. | ||
| 167 | |||
| 168 | If you think you've found a bug then please read "How to Report Bugs | ||
| 169 | Effectively" by Simon Tatham: | ||
| 170 | L<http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>. | ||
| 171 | |||
| 172 | =head1 SUPPORT | ||
| 173 | |||
| 174 | You can find documentation for this module with the perldoc command. | ||
| 175 | |||
| 176 | perldoc Net::Radio::oFono | ||
| 177 | |||
| 178 | You can also look for information at: | ||
| 179 | |||
| 180 | =over 4 | ||
| 181 | |||
| 182 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 183 | |||
| 184 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Radio-oFono> | ||
| 185 | |||
| 186 | If you think you've found a bug then please read "How to Report Bugs | ||
| 187 | Effectively" by Simon Tatham: | ||
| 188 | L<http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>. | ||
| 189 | |||
| 190 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 191 | |||
| 192 | L<http://annocpan.org/dist/Net-Radio-oFono> | ||
| 193 | |||
| 194 | =item * CPAN Ratings | ||
| 195 | |||
| 196 | L<http://cpanratings.perl.org/d/Net-Radio-oFono> | ||
| 197 | |||
| 198 | =item * Search CPAN | ||
| 199 | |||
| 200 | L<http://search.cpan.org/dist/Net-Radio-oFono/> | ||
| 201 | |||
| 202 | =back | ||
| 203 | |||
| 204 | =head2 Where can I go for help with a concrete version? | ||
| 205 | |||
| 206 | Bugs and feature requests are accepted against the latest version | ||
| 207 | only. To get patches for earlier versions, you need to get an | ||
| 208 | agreement with a developer of your choice - who may or not report the | ||
| 209 | issue and a suggested fix upstream (depends on the license you have | ||
| 210 | chosen). | ||
| 211 | |||
| 212 | =head2 Business support and maintenance | ||
| 213 | |||
| 214 | For business support you can contact Jens via his CPAN email | ||
| 215 | address rehsackATcpan.org. Please keep in mind that business | ||
| 216 | support is neither available for free nor are you eligible to | ||
| 217 | receive any support based on the license distributed with this | ||
| 218 | package. | ||
| 219 | |||
| 220 | =head1 ACKNOWLEDGEMENTS | ||
| 221 | |||
| 222 | At first the guys from the oFono-Team shall be named: Marcel Holtmann and | ||
| 223 | Denis Kenzior, the maintainers and all the people named in ofono/AUTHORS. | ||
| 224 | Without their effort, there would no need for a Net::Radio::oFono module. | ||
| 225 | |||
| 226 | Further, Peter "ribasushi" Rabbitson helped a lot by providing hints | ||
| 227 | and support how to make this API accessor a valuable CPAN module. | ||
| 228 | |||
| 229 | =head1 AUTHOR | ||
| 230 | |||
| 231 | Jens Rehsack, C<< <rehsack at cpan.org> >> | ||
| 232 | |||
| 233 | =head1 LICENSE AND COPYRIGHT | ||
| 234 | |||
| 235 | Copyright 2012 Jens Rehsack. | ||
| 236 | |||
| 237 | This program is free software; you can redistribute it and/or modify it | ||
| 238 | under the terms of either: the GNU General Public License as published | ||
| 239 | by the Free Software Foundation; or the Artistic License. | ||
| 240 | |||
| 241 | See http://dev.perl.org/licenses/ for more information. | ||
| 242 | |||
| 243 | |||
| 244 | =cut | ||
| 245 | |||
| 246 | 1; |