2 // This file is part of the aMule Project.
4 // Copyright (c) 2004-2008 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
), m_app(app
)
75 CCommandTree
* AddCommand(const wxString
& command
, int cmd_id
, const wxString
& shortDesc
, const wxString
& longDesc
, enum Params params
= CMD_PARAM_OPTIONAL
)
77 return AddCommand(new CCommandTree(m_app
, command
, cmd_id
, shortDesc
, longDesc
, params
));
80 int FindCommandId(const wxString
& command
, wxString
& args
, wxString
& cmdstr
) const;
81 wxString
GetFullCommand() const;
82 void PrintHelpFor(const wxString
& command
) const;
85 CCommandTree(CaMuleExternalConnector
& app
, const wxString
& command
, int cmd_id
, const wxString
& shortDesc
, const wxString
& longDesc
, enum Params params
)
86 : m_command(command
), m_cmd_id(cmd_id
), m_short(shortDesc
), m_verbose(longDesc
), m_params(params
), m_parent(NULL
), m_app(app
)
89 CCommandTree
* AddCommand(CCommandTree
* cmdTree
);
96 const CCommandTree
* m_parent
;
97 CaMuleExternalConnector
& m_app
;
98 CmdList_t m_subcommands
;
104 class CaMuleExternalConnector
: public wxApp
108 // Constructor & Destructor
110 CaMuleExternalConnector();
111 ~CaMuleExternalConnector();
116 virtual void Pre_Shell() {}
117 virtual void Post_Shell() {}
118 virtual int ProcessCommand(int) { return -1; }
119 virtual void TextShell(const wxString
&prompt
);
120 virtual void LoadConfigFile();
121 virtual void SaveConfigFile();
122 virtual void LoadAmuleConfig(CECFileConfig
& cfg
);
123 virtual void OnInitCommandSet();
124 virtual bool OnInit();
125 virtual const wxString
GetGreetingTitle() = 0;
130 void Show(const wxString
&s
);
131 void DebugShow(const wxString
&s
) { if (m_Verbose
) Show(s
); }
132 const wxString
& GetCmdArgs() const { return m_cmdargs
; }
133 const wxString
& GetLastCmdStr() const { return m_lastcmdstr
; }
134 int GetIDFromString(const wxString
& buffer
) { return m_commands
.FindCommandId(buffer
, m_cmdargs
, m_lastcmdstr
); }
135 void Process_Answer(const wxString
& answer
);
136 bool Parse_Command(const wxString
& buffer
);
137 void GetCommand(const wxString
&prompt
, char* buffer
, size_t buffer_size
);
138 const CECPacket
*SendRecvMsg_v2(const CECPacket
*request
) { return m_ECClient
->SendRecvPacket(request
); }
139 void ConnectAndRun(const wxString
&ProgName
, const wxString
& ProgVersion
);
143 // Command line processing
145 void OnInitCmdLine(wxCmdLineParser
& amuleweb_parser
, const char* appname
);
146 bool OnCmdLineParsed(wxCmdLineParser
& parser
);
148 // Exception and assert handling
149 void OnFatalException();
151 void OnAssertFailure(const wxChar
*file
, int line
, const wxChar
*func
, const wxChar
*cond
, const wxChar
*msg
);
154 CECFileConfig
* m_configFile
;
155 wxString m_configFileName
;
158 // Set current locale, if language is not empty.
159 // returns canonical name of set (current) locale
160 virtual wxString
SetLocale(const wxString
& language
);
168 CCommandTree m_commands
;
169 const char * m_appname
;
171 #if !wxUSE_GUI && defined(__WXMAC__) && !wxCHECK_VERSION(2, 9, 0)
172 virtual wxAppTraits
* CreateTraits();
177 wxString m_lastcmdstr
;
178 CRemoteConnect
* m_ECClient
;
180 bool m_NeedsConfigSave
;
183 char * m_strFullVersion
;
184 char * m_strOSDescription
;
187 #endif // __EXTERNALCONNECTOR_H__
188 // File_checked_for_headers