MongoDB C++ Driver legacy-1.1.2
Loading...
Searching...
No Matches
background.h
1// @file background.h
2
3/* Copyright 2009 10gen Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
20#include <boost/scoped_ptr.hpp>
21#include <boost/utility.hpp>
22#include <string>
23#include <vector>
24
25#include "mongo/base/status.h"
26
27namespace mongo {
28
45class BackgroundJob : boost::noncopyable {
46protected:
53 explicit BackgroundJob(bool selfDelete = false);
54
55 virtual std::string name() const = 0;
56
67 virtual void run() = 0;
68
69public:
70 enum State { NotStarted, Running, Done };
71
72 virtual ~BackgroundJob();
73
81 void go();
82
83
92
102 bool wait(unsigned msTimeOut = 0);
103
104 // accessors. Note that while the access to the internal state is synchronized within
105 // these methods, there is no guarantee that the BackgroundJob is still in the
106 // indicated state after returning.
107 State getState() const;
108 bool running() const;
109
110private:
111 const bool _selfDelete;
112
113 struct JobStatus;
114 const boost::scoped_ptr<JobStatus> _status;
115
116 void jobBody();
117};
118
119} // namespace mongo
Background thread dispatching.
Definition background.h:45
void go()
starts job.
Status cancel()
If the job has not yet started, transitions the job to the 'done' state immediately,...
bool wait(unsigned msTimeOut=0)
wait for completion.
BackgroundJob(bool selfDelete=false)
sub-class must instantiate the BackgroundJob
virtual void run()=0
define this to do your work.
Status represents an error state or the absence thereof.
Definition status.h:50
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20