OLD | NEW |
| (Empty) |
1 // Copyright 2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 | |
16 // Defines the base class of classes in the model. Provides access to the root | |
17 // of the model. | |
18 | |
19 #ifndef OMAHA_GOOPDATE_MODEL_OBJECT_H_ | |
20 #define OMAHA_GOOPDATE_MODEL_OBJECT_H_ | |
21 | |
22 #include <windows.h> | |
23 #include "base/basictypes.h" | |
24 #include "omaha/base/debug.h" | |
25 #include "omaha/base/utils.h" | |
26 | |
27 namespace omaha { | |
28 | |
29 class Model; | |
30 | |
31 bool IsModelLockedByCaller(const Model* model); | |
32 | |
33 class ModelObject { | |
34 public: | |
35 | |
36 Model* model() { | |
37 return omaha::interlocked_exchange_pointer(&model_, model_); | |
38 } | |
39 | |
40 const Model* model() const { | |
41 return omaha::interlocked_exchange_pointer(&model_, model_); | |
42 } | |
43 | |
44 protected: | |
45 | |
46 explicit ModelObject(Model* model) : model_(NULL) { | |
47 ASSERT1(model); | |
48 ASSERT1(IsModelLockedByCaller(model)); | |
49 | |
50 omaha::interlocked_exchange_pointer(&model_, model); | |
51 } | |
52 | |
53 ~ModelObject() { | |
54 omaha::interlocked_exchange_pointer(&model_, static_cast<Model*>(NULL)); | |
55 } | |
56 | |
57 private: | |
58 | |
59 // C++ root of the object model. Not owned by this instance. | |
60 mutable Model* volatile model_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(ModelObject); | |
63 }; | |
64 | |
65 } // namespace omaha | |
66 | |
67 #endif // OMAHA_GOOPDATE_MODEL_OBJECT_H_ | |
68 | |
OLD | NEW |