Project

General

Profile

Task #1290

Updated by Junxiao Shi over 10 years ago

Create a global instance of `io_service` io_service and `Scheduler`. Scheduler. 

     namespace nfd { 
     boost::asio::io_service& getGlobalIoService(); 
    
     namespace scheduler { 
     struct EventId; 
     typedef function<void()> Event; 
     EventId schedule(time::Duration after, Event event); 
     void cancel(const EventId& eventId); 
     } // namespace scheduler 
     using scheduler::EventId; // import to nfd namespace 
    
     } // namespace nfd 

 The global instances can be replaced/cleared/reset replaced/clearer/reset during unit testing. 

 --- 

 This task is divided to two stages: 

 ## Stage 1 

 * Create global `io_service` and `Scheduler`. 
 * `nfd::Scheduler` class still exists. Its global instance is accessed at `nfd::getGlobalScheduler()`. 
 * Use the global `io_service` in `main()`. 
 * Add a zero argument constructor to `Forwarder` which uses the global `Scheduler`. 
 * Unit tests still have their own `io_service` and `Scheduler`. 

 ## Stage 2 

 * Delete references to `io_service` and `Scheduler` in all classes and constructors. 
 * Change all scheduler calls to use `nfd::scheduler::schedule` and `nfd::scheduler::cancel`. 
 * Delete or move away `nfd::Scheduler` class. Delete `nfd::getGlobalScheduler()` function. 
 * Unit tests also use the global instances, and are provided a way to reset / replace the global `io_service` and `Scheduler`. 

Back