Home » Developing U++ » UppHub » FTP class and reference example for U++
Re: FTP class and reference example for U++ [message #47882 is a reply to message #47877] |
Sun, 16 April 2017 18:28   |
Oblivion
Messages: 1037 Registered: August 2007
|
Senior Contributor |
|
|
Quote:Hello,
In my opinion handling multi-threading API using #ifdef in header is not good for the end user. Because, he/seh is obligated to use #ifdef in theire code. Personally, i would hide it inside the interface and use One container (Movable will not work for this class).
class Result // Interface - all methods are abstract
{
public:
// The same as previous
virtual bool IsAsync() = 0;
// Mt methods are presented without #ifdef guard
};
class RegularResult : public Result // The name could be different
{
public:
bool IsAsync() override { return false; }
// Mt methods returning falses, -1 etc.
};
class AsyncResult : public Result
{
public:
bool IsAsync() override { return true; }
// Return correct values for MT
};
One<Result> result(new AsyncResult());
What do you think?
Sincerely,
Klugier
Hello Klugier,
Thank you very much for your constructive criticism and suggestions.
I believe we might have a simpler solution. 
FtpAsyncGet() and FtpAsyncPut() functions call FtpAsyncIO().It is possible to return en error code if anything goes wrong.
So we can simply define a function, say, IsMultitihreaded(), to check the U++ multi-threading infrastructure automatically, in Ftp.cpp:
static inline bool IsMultithreaded()
{
#ifdef flagMT
return true;
#else
return false;
#endif
}
Then we can call it in FtpAsyncIO:
Ftp::Result FtpAsyncIO(Ftp::Request request, Event<Ftp::Result> progress, bool put)
{
// Check if U++ MT is enabled.
Ftp::Result r;
try {
if(!IsMultithreaded())
throw Exc("Multithreading is not enabled.");
// ...
}
catch(Exc& e) {
// Couldn'r create or run the worker thread.
r.info("state") = "failed";
r.info("rc") = -1;
r.info("msg") = e;
LLOG("-- FTP worker failed. Reason: " << e);
}
return r;
In this way we can remove other ifdefs, and user won't be confused.
(Multithreading as a requirement is already mentioned in API docs for each method and function. )
Note that I also changed the return value from int to Ftp::Result. (Now they are similar to single-threaded variants)
Calling an async function such as Result::InProgress() now won't do harm, it wil silently return false.
AS for your other suggestions:
ParseFtpDirEntry() actually modifies the ValueMap. It parses the string into key-value pairs. However, now I put the actual parser code into DirEntry::Parser() method, and got rid of the friend declaration.
Same thing goes for the Request class. So, the ugly forward declarations are removed.
I updated the package to reflect the changes...
Regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
[Updated on: Sun, 16 April 2017 20:01] Report message to a moderator
|
|
|
 |
|
FTP class and reference example for U++
By: Oblivion on Sun, 27 April 2014 18:11
|
 |
|
Re: FTP class and reference example for U++
|
 |
|
Re: FTP class and reference example for U++
|
 |
|
Re: FTP class and reference example for U++
|
 |
|
Re: FTP class and reference example for U++
By: mirek on Wed, 14 May 2014 09:25
|
 |
|
Re: FTP class and reference example for U++
|
 |
|
Re: FTP class and reference example for U++
By: Oblivion on Wed, 12 April 2017 22:34
|
 |
|
Re: FTP class and reference example for U++
By: Klugier on Wed, 12 April 2017 23:05
|
 |
|
Re: FTP class and reference example for U++
By: Oblivion on Thu, 13 April 2017 08:17
|
 |
|
Re: FTP class and reference example for U++
|
 |
|
Re: FTP class and reference example for U++
By: Oblivion on Thu, 13 April 2017 13:55
|
 |
|
Re: FTP class and reference example for U++
By: Oblivion on Fri, 14 April 2017 23:45
|
 |
|
Re: FTP class and reference example for U++
By: Klugier on Sat, 15 April 2017 19:23
|
 |
|
Re: FTP class and reference example for U++
By: Klugier on Sat, 15 April 2017 19:38
|
 |
|
Re: FTP class and reference example for U++
By: Oblivion on Sun, 16 April 2017 18:28
|
 |
|
Re: FTP class and reference example for U++
By: Oblivion on Wed, 24 December 2014 12:06
|
 |
|
Re: FTP class and reference example for U++
By: Oblivion on Thu, 25 December 2014 18:03
|
 |
|
Re: FTP class and reference example for U++
By: Oblivion on Wed, 07 January 2015 20:52
|
 |
|
Re: FTP class and reference example for U++
By: Oblivion on Tue, 20 January 2015 01:17
|
 |
|
Re: FTP class and reference example for U++
By: unodgs on Tue, 07 July 2015 19:40
|
 |
|
Re: FTP class and reference example for U++
|
 |
|
Re: FTP class and reference example for U++
By: unodgs on Wed, 08 July 2015 10:20
|
 |
|
Re: FTP class and reference example for U++
By: Oblivion on Sat, 18 March 2017 23:28
|
 |
|
Re: FTP class and reference example for U++
By: Oblivion on Sun, 09 April 2017 02:32
|
 |
|
Re: FTP class and reference example for U++
By: Oblivion on Sun, 23 April 2017 23:41
|
 |
|
Re: FTP class and reference example for U++
By: Oblivion on Mon, 24 April 2017 19:01
|
 |
|
Re: FTP class and reference example for U++
By: Klugier on Mon, 24 April 2017 22:12
|
 |
|
Re: FTP class and reference example for U++
By: Oblivion on Tue, 25 April 2017 08:37
|
 |
|
Re: FTP class and reference example for U++
|
 |
|
Re: FTP class and reference example for U++
By: Tom1 on Fri, 16 June 2017 10:23
|
 |
|
Re: FTP class and reference example for U++
|
 |
|
Re: FTP class and reference example for U++
By: Oblivion on Mon, 02 April 2018 00:17
|
Goto Forum:
Current Time: Mon Jun 05 19:51:00 CEST 2023
Total time taken to generate the page: 0.01160 seconds
|