Commit 29121937 authored by Davis King's avatar Davis King

Turned timeout into a single implementation style object. Therefore, now it

can be declared as a type timeout rather than timeout::kernel_1a.

--HG--
rename : dlib/timeout/timeout_kernel_1.h => dlib/timeout/timeout.h
rename : dlib/timeout/timeout_kernel_abstract.h => dlib/timeout/timeout_abstract.h
parent 83ff1e3e
...@@ -3,26 +3,7 @@ ...@@ -3,26 +3,7 @@
#ifndef DLIB_TIMEOUt_ #ifndef DLIB_TIMEOUt_
#define DLIB_TIMEOUt_ #define DLIB_TIMEOUt_
#include "timeout/timeout_kernel_1.h" #include "timeout/timeout.h"
namespace dlib
{
class timeout
{
timeout() {}
public:
//----------- kernels ---------------
// kernel_1a
typedef timeout_kernel_1
kernel_1a;
};
}
#endif // DLIB_TIMEOUt_ #endif // DLIB_TIMEOUt_
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "../threads.h" #include "../threads.h"
#include "../algs.h" #include "../algs.h"
#include "../misc_api.h" #include "../misc_api.h"
#include "timeout_kernel_abstract.h" #include "timeout_abstract.h"
#include "../uintn.h" #include "../uintn.h"
#include "../timer.h" #include "../timer.h"
...@@ -23,7 +23,7 @@ namespace dlib ...@@ -23,7 +23,7 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
class timeout_kernel_1 class timeout
{ {
/*! /*!
INITIAL VALUE INITIAL VALUE
...@@ -62,15 +62,18 @@ namespace dlib ...@@ -62,15 +62,18 @@ namespace dlib
public: public:
// This typedef is here for backwards compatibility with previous versions of dlib.
typedef timeout kernel_1a;
template < template <
typename T typename T
> >
timeout_kernel_1 ( timeout (
T& object, T& object,
void (T::*callback_function)(), void (T::*callback_function)(),
unsigned long ms_to_timeout unsigned long ms_to_timeout
): ):
t(*this,&timeout_kernel_1::trigger_timeout) t(*this,&timeout::trigger_timeout)
{ {
zero<T,void>* B = new zero<T,void>; zero<T,void>* B = new zero<T,void>;
b = B; b = B;
...@@ -84,13 +87,13 @@ namespace dlib ...@@ -84,13 +87,13 @@ namespace dlib
typename T, typename T,
typename U typename U
> >
timeout_kernel_1 ( timeout (
T& object, T& object,
void (T::*callback_function)(U callback_function_argument), void (T::*callback_function)(U callback_function_argument),
unsigned long ms_to_timeout, unsigned long ms_to_timeout,
U callback_function_argument U callback_function_argument
): ):
t(*this,&timeout_kernel_1::trigger_timeout) t(*this,&timeout::trigger_timeout)
{ {
one<T,void,U>* B = new one<T,void,U>; one<T,void,U>* B = new one<T,void,U>;
b = B; b = B;
...@@ -104,12 +107,12 @@ namespace dlib ...@@ -104,12 +107,12 @@ namespace dlib
template < template <
typename T typename T
> >
timeout_kernel_1 ( timeout (
T& object, T& object,
int (T::*callback_function)(), int (T::*callback_function)(),
unsigned long ms_to_timeout unsigned long ms_to_timeout
): ):
t(*this,&timeout_kernel_1::trigger_timeout) t(*this,&timeout::trigger_timeout)
{ {
zero<T,int>* B = new zero<T,int>; zero<T,int>* B = new zero<T,int>;
b = B; b = B;
...@@ -123,13 +126,13 @@ namespace dlib ...@@ -123,13 +126,13 @@ namespace dlib
typename T, typename T,
typename U typename U
> >
timeout_kernel_1 ( timeout (
T& object, T& object,
int (T::*callback_function)(U callback_function_argument), int (T::*callback_function)(U callback_function_argument),
unsigned long ms_to_timeout, unsigned long ms_to_timeout,
U callback_function_argument U callback_function_argument
): ):
t(*this,&timeout_kernel_1::trigger_timeout) t(*this,&timeout::trigger_timeout)
{ {
one<T,int,U>* B = new one<T,int,U>; one<T,int,U>* B = new one<T,int,U>;
b = B; b = B;
...@@ -140,7 +143,7 @@ namespace dlib ...@@ -140,7 +143,7 @@ namespace dlib
t.start(); t.start();
} }
virtual ~timeout_kernel_1 ( virtual ~timeout (
) )
{ {
t.stop_and_wait(); t.stop_and_wait();
...@@ -155,12 +158,12 @@ namespace dlib ...@@ -155,12 +158,12 @@ namespace dlib
t.stop(); t.stop();
} }
dlib::timer<timeout_kernel_1>::kernel_2a t; dlib::timer<timeout>::kernel_2a t;
bind* b; bind* b;
// restricted functions // restricted functions
timeout_kernel_1(const timeout_kernel_1&); // copy constructor timeout(const timeout&); // copy constructor
timeout_kernel_1& operator=(const timeout_kernel_1&); // assignment operator timeout& operator=(const timeout&); // assignment operator
}; };
......
...@@ -20,7 +20,7 @@ namespace dlib ...@@ -20,7 +20,7 @@ namespace dlib
connection* con = a connection from somewhere; connection* con = a connection from somewhere;
{ {
// setup a timer that will call con->shutdown() in 10 seconds // setup a timer that will call con->shutdown() in 10 seconds
timeout::kernel_1a t(*con,&connection::shutdown,10000); timeout t(*con,&connection::shutdown,10000);
// Now call read on the connection. If this call to read() takes // Now call read on the connection. If this call to read() takes
// more than 10 seconds then the t timeout will trigger and shutdown // more than 10 seconds then the t timeout will trigger and shutdown
// the connection. If read completes in less than 10 seconds then // the connection. If read completes in less than 10 seconds then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment