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