VSM C++ SDK
Vehicle Specific Modules SDK
shared_memory.h
1 // Copyright (c) 2014, 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 SHARED_MEMORY_H_
13 #define 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:
52 
54  typedef enum {
55  OPEN_RESULT_OK,
56  OPEN_RESULT_CREATED,
57  OPEN_RESULT_ERROR
58  } Open_result;
59 
65  memory(nullptr)
66  {};
67 
68  virtual
69  ~Shared_memory(){};
70 
81  virtual Open_result
82  Open(const std::string& name, const size_t size) = 0;
83 
87  virtual void
88  Close() = 0;
89 
94  virtual void*
95  Get() {return memory;};
96 
104  static bool
105  Delete(const std::string& name);
106 
113  static Ptr
114  Create();
115 
117 protected:
118  void* memory;
119 };
120 
121 } /* namespace vsm */
122 } /* namespace ugcs */
123 #endif /* SHARED_MEMORY_H_ */
UGCS root namespace.
Definition: android-linux/ugcs/vsm/platform_sockets.h:27
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:64
virtual void * Get()
Returns the pointer to shared memory.
Definition: shared_memory.h:95
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:54
#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:118
virtual void Close()=0
Closes previously opened memory.