| 1 | package VoiceXML::Client::Engine::Component; | ||
| 2 | |||
| 3 | use VoiceXML::Client::Util; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | |||
| 7 | |||
| 8 | |||
| 9 | =head1 COPYRIGHT AND LICENSE | ||
| 10 | |||
| 11 | |||
| 12 | Copyright (C) 2007,2008 by Pat Deegan. | ||
| 13 | All rights reserved | ||
| 14 | http://voicexml.psychogenic.com | ||
| 15 | |||
| 16 | This library is released under the terms of the GNU GPL version 3, making it available only for | ||
| 17 | free programs ("free" here being used in the sense of the GPL, see http://www.gnu.org for more details). | ||
| 18 | Anyone wishing to use this library within a proprietary or otherwise non-GPLed program MUST contact psychogenic.com to | ||
| 19 | acquire a distinct license for their application. This approach encourages the use of free software | ||
| 20 | while allowing for proprietary solutions that support further development. | ||
| 21 | |||
| 22 | |||
| 23 | This file is part of VoiceXML::Client. | ||
| 24 | |||
| 25 | |||
| 26 | |||
| 27 | VoiceXML::Client is free software: you can redistribute it and/or modify | ||
| 28 | it under the terms of the GNU General Public License as published by | ||
| 29 | the Free Software Foundation, either version 3 of the License, or | ||
| 30 | (at your option) any later version. | ||
| 31 | |||
| 32 | VoiceXML::Client is distributed in the hope that it will be useful, | ||
| 33 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 34 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 35 | GNU General Public License for more details. | ||
| 36 | |||
| 37 | You should have received a copy of the GNU General Public License | ||
| 38 | along with VoiceXML::Client. If not, see <http://www.gnu.org/licenses/>. | ||
| 39 | |||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | |||
| 44 | =head2 DESCRIPTION | ||
| 45 | |||
| 46 | The VXML::Engine uses a number of components. These components serve to abstract | ||
| 47 | away platform specific details, such as supported voice device hardware, TTS engines | ||
| 48 | etc. | ||
| 49 | |||
| 50 | All components must use the VoiceXML::Client::Engine::Component as a base class (possibly | ||
| 51 | indirectly, through multi-leveled inheritance). The VoiceXML::Client::Engine::Component serves | ||
| 52 | as an abstract base class for all components, thereby assuring the engine that all it's | ||
| 53 | components will provide a minimal common interface. | ||
| 54 | |||
| 55 | The VoiceXML::Client::Engine::Component class also implements the functionality that allows | ||
| 56 | components to interact with other components, while using the engine as a mediator - thus | ||
| 57 | eliminating any component interdependance (see the engineRequest() method); Components only | ||
| 58 | know about the engine and the engine only guarantees that it will attempt to fullfill the | ||
| 59 | request and will not die in the process. | ||
| 60 | |||
| 61 | =head2 NOTES | ||
| 62 | |||
| 63 | Subclasses of Component may not use the reserved _component_ keyword as the first part | ||
| 64 | of object hash keys (eg $self->{'_component_blah'}). | ||
| 65 | |||
| 66 | |||
| 67 | =head2 new ENGINEOBJ [PARAMS] | ||
| 68 | |||
| 69 | =cut | ||
| 70 | |||
| 71 | sub new { | ||
| 72 | my $class = shift; | ||
| 73 | my $engine = shift; | ||
| 74 | my $params = shift; | ||
| 75 | |||
| 76 | |||
| 77 | my $self = {}; | ||
| 78 | |||
| 79 | bless $self, ref $class || $class; | ||
| 80 | |||
| 81 | |||
| 82 | VoiceXML::Client::Util::error("Must pass an engine mediator object to VoiceXML::Client::Engine::Component::new()") | ||
| 83 | unless ($engine); | ||
| 84 | |||
| 85 | $self->{'_component_type'} = ref $class || $class; | ||
| 86 | |||
| 87 | $self->{'_component_engine'} = $engine; | ||
| 88 | |||
| 89 | $self->init($params); | ||
| 90 | |||
| 91 | return $self; | ||
| 92 | } | ||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | sub init { | ||
| 97 | my $self = shift; | ||
| 98 | my $params = shift; | ||
| 99 | |||
| 100 | return 1; | ||
| 101 | } | ||
| 102 | |||
| 103 | |||
| 104 | =head2 engineRequest TYPE [PARAM1 [PARAM2] [...]] | ||
| 105 | |||
| 106 | All components may request actions from the engine, using the engineRequest method. This method serves to mediate | ||
| 107 | requests between components. For instance, a document fetcher may request the engine play background music while | ||
| 108 | fetching a document, then request the engine stop playing music when done - all without the fetcher knowing anything | ||
| 109 | about the audio components (Audio::Output and Audio::Device) involved in the activity. | ||
| 110 | |||
| 111 | =cut | ||
| 112 | |||
| 113 | sub engineRequest { | ||
| 114 | my $self = shift; | ||
| 115 | my $request = shift; | ||
| 116 | |||
| 117 | |||
| 118 | return $self->{'_component_engine'}->componentRequest($self, $request, @_); | ||
| 119 | } | ||
| 120 | |||
| 121 | |||
| 122 | 1; |