• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //    * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //    * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //    * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 #ifndef CEF_INCLUDE_CAPI_CEF_BASE_CAPI_H_
31 #define CEF_INCLUDE_CAPI_CEF_BASE_CAPI_H_
32 
33 #include <stdint.h>
34 
35 #include "include/internal/cef_export.h"
36 #include "include/internal/cef_string.h"
37 #include "include/internal/cef_string_list.h"
38 #include "include/internal/cef_string_map.h"
39 #include "include/internal/cef_string_multimap.h"
40 #include "include/internal/cef_types.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 ///
47 // All ref-counted framework structures must include this structure first.
48 ///
49 typedef struct _cef_base_ref_counted_t {
50   ///
51   // Size of the data structure.
52   ///
53   size_t size;
54 
55   ///
56   // Called to increment the reference count for the object. Should be called
57   // for every new copy of a pointer to a given object.
58   ///
59   void(CEF_CALLBACK* add_ref)(struct _cef_base_ref_counted_t* self);
60 
61   ///
62   // Called to decrement the reference count for the object. If the reference
63   // count falls to 0 the object should self-delete. Returns true (1) if the
64   // resulting reference count is 0.
65   ///
66   int(CEF_CALLBACK* release)(struct _cef_base_ref_counted_t* self);
67 
68   ///
69   // Returns true (1) if the current reference count is 1.
70   ///
71   int(CEF_CALLBACK* has_one_ref)(struct _cef_base_ref_counted_t* self);
72 
73   ///
74   // Returns true (1) if the current reference count is at least 1.
75   ///
76   int(CEF_CALLBACK* has_at_least_one_ref)(struct _cef_base_ref_counted_t* self);
77 } cef_base_ref_counted_t;
78 
79 ///
80 // All scoped framework structures must include this structure first.
81 ///
82 typedef struct _cef_base_scoped_t {
83   ///
84   // Size of the data structure.
85   ///
86   size_t size;
87 
88   ///
89   // Called to delete this object. May be NULL if the object is not owned.
90   ///
91   void(CEF_CALLBACK* del)(struct _cef_base_scoped_t* self);
92 
93 } cef_base_scoped_t;
94 
95 // Check that the structure |s|, which is defined with a size_t member at the
96 // top, is large enough to contain the specified member |f|.
97 #define CEF_MEMBER_EXISTS(s, f) \
98   ((intptr_t) &                 \
99    ((s)->f) - (intptr_t)(s) + sizeof((s)->f) <= *reinterpret_cast<size_t*>(s))
100 
101 #define CEF_MEMBER_MISSING(s, f) (!CEF_MEMBER_EXISTS(s, f) || !((s)->f))
102 
103 #ifdef __cplusplus
104 }
105 #endif
106 
107 #endif  // CEF_INCLUDE_CAPI_CEF_BASE_CAPI_H_
108