MongoDB C++ Driver  legacy-1.0.3
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 
27 namespace mongo {
28 
45  class BackgroundJob : boost::noncopyable {
46  protected:
53  explicit BackgroundJob(bool selfDelete = false);
54 
55  virtual std::string name() const = 0;
56 
67  virtual void run() = 0;
68 
69  public:
70  enum State {
71  NotStarted,
72  Running,
73  Done
74  };
75 
76  virtual ~BackgroundJob();
77 
85  void go();
86 
87 
95  Status cancel();
96 
106  bool wait( unsigned msTimeOut = 0 );
107 
108  // accessors. Note that while the access to the internal state is synchronized within
109  // these methods, there is no guarantee that the BackgroundJob is still in the
110  // indicated state after returning.
111  State getState() const;
112  bool running() const;
113 
114  private:
115  const bool _selfDelete;
116 
117  struct JobStatus;
118  const boost::scoped_ptr<JobStatus> _status;
119 
120  void jobBody();
121  };
122 
123 } // namespace mongo
Status cancel()
If the job has not yet started, transitions the job to the 'done' state immediately, such that subsequent calls to 'go' are ignored, and notifies any waiters waiting in 'wait'.
the main MongoDB namespace
Definition: bulk_operation_builder.h:24
void go()
starts job.
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.
Background thread dispatching.
Definition: background.h:45
MONGO_CLIENT_API Status(MONGO_CLIENT_FUNC *saslClientAuthenticate)(DBClientWithCommands *client
Attempts to authenticate "client" using the SASL protocol.