VSM C++ SDK
Vehicle Specific Modules SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
shared_memory.h
1 // Copyright (c) 2018, Smart Projects Holdings Ltd
2 // All rights reserved.
3 // See LICENSE file for license details.
4 
5 /*
6  * shared_memory.h
7  *
8  * Created on: Oct 24, 2013
9  * Author: Janis
10  */
11 
12 #ifndef _UGCS_VSM_SHARED_MEMORY_H_
13 #define _UGCS_VSM_SHARED_MEMORY_H_
14 
15 #include <ugcs/vsm/utils.h>
16 
17 namespace ugcs {
18 namespace vsm {
19 
48 class Shared_memory: public std::enable_shared_from_this<Shared_memory>
49 {
51 public:
53  typedef enum {
54  OPEN_RESULT_OK,
55  OPEN_RESULT_CREATED,
56  OPEN_RESULT_ERROR
57  } Open_result;
58 
64  memory(nullptr)
65  {};
66 
67  virtual
68  ~Shared_memory() {}
69 
80  virtual Open_result
81  Open(const std::string& name, const size_t size) = 0;
82 
86  virtual void
87  Close() = 0;
88 
93  virtual void*
94  Get() {return memory;}
95 
103  static bool
104  Delete(const std::string& name);
105 
112  static Ptr
113  Create();
114 
116 protected:
117  void* memory;
118 };
119 
120 } /* namespace vsm */
121 } /* namespace ugcs */
122 #endif /* _UGCS_VSM_SHARED_MEMORY_H_ */
Platform independent implementation of system-wide named shared memory used for interprocess communic...
Definition: shared_memory.h:48
Shared_memory()
Constructor should not be called explicitly.
Definition: shared_memory.h:63
virtual void * Get()
Returns the pointer to shared memory.
Definition: shared_memory.h:94
std::shared_ptr< Shared_memory > Ptr
Pointer type.
Definition: shared_memory.h:50
Various common utilities.
virtual Open_result Open(const std::string &name, const size_t size)=0
Open/create shared memory.
static Ptr Create()
Creates Platform specific class instance.
static bool Delete(const std::string &name)
Deletes the named memory.
Open_result
Possible return codes from Open() call.
Definition: shared_memory.h:53
#define DEFINE_COMMON_CLASS(__class_name,...)
Use this macro to define some common attributes for a class.
Definition: utils.h:25
void * memory
pointer to shared memory
Definition: shared_memory.h:117
virtual void Close()=0
Closes previously opened memory.