2 // This file is part of the aMule Project.
4 // Copyright (c) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 * This file must be included with wxUSE_GUI defined to zero or one.
27 * Usually on console applications, this will be taken care of in
28 * configure time. This is because wx classes will be compiled
29 * differently in each case.
33 #ifndef __EXTERNALCONNECTOR_H__
34 #define __EXTERNALCONNECTOR_H__
36 #include <wx/app.h> // For wxApp
37 #include <wx/cmdline.h> // For wxCmdLineEntryDesc
38 #include <ec/cpp/RemoteConnect.h>
42 #define CMD_DEPRECATED 0x1000
44 #define CMD_ID_QUIT -1
45 #define CMD_ID_HELP -2
46 #define CMD_ERR_SYNTAX -3
47 #define CMD_ERR_PROCESS_CMD -4
48 #define CMD_ERR_NO_PARAM -5
49 #define CMD_ERR_MUST_HAVE_PARAM -6
50 #define CMD_ERR_INVALID_ARG -7
51 #define CMD_ERR_INCOMPLETE -8
61 typedef std::list
<const CCommandTree
*> CmdList_t
;
62 typedef std::list
<const CCommandTree
*>::iterator CmdPos_t
;
63 typedef std::list
<const CCommandTree
*>::const_iterator CmdPosConst_t
;
65 class CaMuleExternalConnector
;
69 CCommandTree(CaMuleExternalConnector
& app
)
70 : m_command(wxEmptyString
), m_cmd_id(CMD_ERR_SYNTAX
), m_short(wxEmptyString
), m_verbose(wxEmptyString
), m_params(CMD_PARAM_OPTIONAL
), m_parent(NULL
)
77 CCommandTree
* AddCommand(const wxString
& command
, int cmd_id
, const wxString
& shortDesc
, const wxString
& longDesc
, enum Params params
= CMD_PARAM_OPTIONAL
)
79 return AddCommand(new CCommandTree(command
, cmd_id
, shortDesc
, longDesc
, params
));
82 int FindCommandId(const wxString
& command
, wxString
& args
, wxString
& cmdstr
) const;
83 wxString
GetFullCommand() const;
84 void PrintHelpFor(const wxString
& command
) const;
86 #ifdef HAVE_LIBREADLINE
87 const CmdList_t
* GetSubCommandsFor(const wxString
& command
, bool mayRestart
= true) const;
88 const wxString
& GetCommand() const { return m_command
; }
92 CCommandTree(const wxString
& command
, int cmd_id
, const wxString
& shortDesc
, const wxString
& longDesc
, enum Params params
)
93 : m_command(command
), m_cmd_id(cmd_id
), m_short(shortDesc
), m_verbose(longDesc
), m_params(params
), m_parent(NULL
)
96 CCommandTree
* AddCommand(CCommandTree
* cmdTree
);
102 enum Params m_params
;
103 const CCommandTree
* m_parent
;
104 CmdList_t m_subcommands
;
106 static CaMuleExternalConnector
* m_app
;
112 class CaMuleExternalConnector
: public wxApp
116 // Constructor & Destructor
118 CaMuleExternalConnector();
119 ~CaMuleExternalConnector();
124 virtual void Pre_Shell() {}
125 virtual void Post_Shell() {}
126 virtual int ProcessCommand(int) { return -1; }
127 virtual void TextShell(const wxString
&prompt
);
128 virtual void LoadConfigFile();
129 virtual void SaveConfigFile();
130 virtual void LoadAmuleConfig(CECFileConfig
& cfg
);
131 virtual void OnInitCommandSet();
132 virtual bool OnInit();
133 virtual const wxString
GetGreetingTitle() = 0;
138 void Show(const wxString
&s
);
139 void DebugShow(const wxString
&s
) { if (m_Verbose
) Show(s
); }
140 const wxString
& GetCmdArgs() const { return m_cmdargs
; }
141 const wxString
& GetLastCmdStr() const { return m_lastcmdstr
; }
142 int GetIDFromString(const wxString
& buffer
) { return m_commands
.FindCommandId(buffer
, m_cmdargs
, m_lastcmdstr
); }
143 void Process_Answer(const wxString
& answer
);
144 bool Parse_Command(const wxString
& buffer
);
145 void GetCommand(const wxString
&prompt
, char* buffer
, size_t buffer_size
);
146 const CECPacket
*SendRecvMsg_v2(const CECPacket
*request
) { return m_ECClient
->SendRecvPacket(request
); }
147 void SendPacket(const CECPacket
*request
) { m_ECClient
->SendPacket(request
); }
148 void ConnectAndRun(const wxString
&ProgName
, const wxString
& ProgVersion
);
152 // Command line processing
154 void OnInitCmdLine(wxCmdLineParser
& amuleweb_parser
, const char* appname
);
155 bool OnCmdLineParsed(wxCmdLineParser
& parser
);
157 #if wxUSE_ON_FATAL_EXCEPTION
158 // Exception and assert handling
159 void OnFatalException();
162 void OnAssertFailure(const wxChar
*file
, int line
, const wxChar
*func
, const wxChar
*cond
, const wxChar
*msg
);
166 // Set current locale, if language is not empty.
167 // returns canonical name of set (current) locale
168 virtual wxString
SetLocale(const wxString
& language
);
170 CECFileConfig
* m_configFile
;
171 wxString m_configDir
;
179 CCommandTree m_commands
;
180 const char * m_appname
;
182 #if !wxUSE_GUI && defined(__WXMAC__) && !wxCHECK_VERSION(2, 9, 0)
183 virtual wxAppTraits
* CreateTraits();
187 wxString m_configFileName
;
189 wxString m_lastcmdstr
;
190 CRemoteConnect
* m_ECClient
;
192 bool m_NeedsConfigSave
;
195 char * m_strFullVersion
;
196 char * m_strOSDescription
;
199 #endif // __EXTERNALCONNECTOR_H__
200 // File_checked_for_headers