00001 00002 // Name: tts_process.h 00003 // Purpose: Helpers for external process TTS handlers 00004 // Author: Julian Smart 00005 // Modified by: 00006 // Created: 2009-02-10 00007 // RCS-ID: 00008 // Copyright: (c) Julian Smart 00009 // Licence: New BSD License 00011 00012 #ifndef _WX_TTS_PROCESS_ 00013 #define _WX_TTS_PROCESS_ 00014 00015 /* 00016 * Includes 00017 */ 00018 00019 #include "wx/process.h" 00020 #include "tts/tts.h" 00021 00028 class wxTTSExternalCommandHandlerProcess; 00029 00030 class wxTTSExternalCommandHandler: public wxTTSHandler 00031 { 00032 DECLARE_CLASS( wxTTSExternalCommandHandler ) 00033 00034 public: 00035 // Constructors 00036 00037 wxTTSExternalCommandHandler(const wxString& id, const wxString& displayName); 00038 ~wxTTSExternalCommandHandler(); 00039 00040 // Operations 00041 00043 void Init(); 00044 00046 virtual bool Initialize() { return true; } 00047 00049 virtual bool Uninitialize() { return true; } 00050 00052 virtual bool IsSpeaking() const { return (GetProcess() != NULL); } 00053 00055 virtual bool Stop(); 00056 00058 virtual bool Launch(const wxString& cmd, int options); 00059 00061 virtual bool VoicesAreCompatible(const wxString& voice1, const wxString& voice2) const; 00062 00064 void SetLastCommand(const wxString& command) { m_command = command; } 00065 wxString GetLastCommand() const { return m_command; } 00066 00068 void SetErrorCode(int errorCode) { m_errorCode = errorCode; } 00069 int GetErrorCode() const { return m_errorCode; } 00070 00072 void SetPID(long pid) { m_pid = pid; } 00073 long GetPID() const { return m_pid; } 00074 00076 void SetOutput(const wxArrayString& output) { m_output = output; } 00077 const wxArrayString& GetOutput() const { return m_output; } 00078 00080 virtual bool ProcessInput(); 00081 00083 virtual void WriteOutput(const wxString& output) { m_output.Add(output); } 00084 00086 void SetProcess(wxTTSExternalCommandHandlerProcess* process) { m_process = process; } 00087 wxTTSExternalCommandHandlerProcess* GetProcess() const { return m_process; } 00088 00091 static bool IsStopping() { return sm_stopping > 0; } 00092 00093 protected: 00094 wxString m_command; 00095 wxArrayString m_output; 00096 int m_errorCode; 00097 wxTTSExternalCommandHandlerProcess* m_process; 00098 long m_pid; 00099 static int sm_stopping; 00100 }; 00101 00106 class wxTTSExternalCommandHandlerProcess: public wxProcess 00107 { 00108 public: 00109 DECLARE_CLASS(wxTTSExternalCommandHandlerProcess) 00110 00111 wxTTSExternalCommandHandlerProcess(const wxString& cmd, wxTTSExternalCommandHandler* speechHandler, wxEvtHandler* handler): wxProcess(handler, wxPROCESS_REDIRECT), m_cmd(cmd) 00112 { 00113 m_eventHandler = handler; 00114 m_handler = speechHandler; 00115 Redirect(); 00116 } 00117 00118 virtual void OnTerminate(int pid, int status); 00119 00120 virtual bool HasInput(); 00121 00122 protected: 00123 wxString m_cmd; 00124 wxEvtHandler* m_eventHandler; 00125 wxTTSExternalCommandHandler* m_handler; 00126 }; 00127 00128 #endif 00129 // _WX_TTS_PROCESS_