Hello,
as already mentioned here on this list, I'm working on the
cxxtools::Timespan class. Now there occurred one problem.
I started to use the cxxtools::Timespan class in some classes, where a
timespan must be specified. For example in cxxtools::Condition. The
class supports a timed wait, where a timeout can be specified.
Previously the timeout value was a number of milliseconds. So to wait
for a condition for 1 second, the use has to specify the value 1000:
cxxtools::Condition someCond;
someCond.wait(lock, 1000);
So far so good. It is quite obvious, what the user expects. A value of
1000 is quite obviously the number of milliseconds. But what if the
timeout is just one millisecond? The code is here:
someCond.wait(lock, 1);
When you just see that code fragment. It is not that clear. It may be 1
millisecond or 1 second. Or maybe another unit.
Now the timeout is specified as a Timespan. In conjunction with the
helper functions, a waif for 1 millisecond is written like that:
someCond.wait(lock, cxxtools::milliseconds(1));
Waiting for a second is here:
someCond.wait(lock, cxxtools::seconds(1));
I think it is now really obvious, what is done here. For compatibility
the timeout can still be specified as a number of milliseconds. This
compatibility method works everywhere, where a timespan as a parameter
is expected.
But for getters it is not possible to keep the API compatible.
As a example lets take the timeout in cxxtools::RemoteClient. There is a
method timeout(std::size_t t), which sets the timeout to the number of
milliseconds. A new method timeout(cxxtools::Timespan t) can be
implemented to set the timeout with a timespan as above.
The getter method timeout() currently returns a std::size_t. If I change
the method to return a cxxtools::Timespan, old code is not compatible
any more:
cxxtools::xmlrpc::HttpClient client(...); // this is a derived from
cxxtools::RemoteClient
unsigned timeoutMs = client.timeout(); // works now but won't
work, when timeout() returns a Timespan
One option is to offer a default cast operator from cxxtools::Timespan
to int or double and return the number of milliseconds, held by the
Timespan object. Then the above works again. But I don't really like the
solution. Why should the Timespan object return the number of
milliseconds? Why not microseconds, since the class has microseconds
resolution? Or maybe seconds since seconds are commonly the base unit
for timespans?
I don't really see a good solution for that, other than keeping
everything as it is. Any ideas?
Tommi
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general