summaryrefslogtreecommitdiff
path: root/ace/SV_Shared_Memory.h
blob: 73b33d75c0b8a2a86fd8719e36ded751feca9296 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* -*- C++ -*- */
// $Id$


// ============================================================================
//
// = LIBRARY
//    ace
//
// = FILENAME
//    SV_Shared_Memory.h
//
// = AUTHOR
//    Doug Schmidt
//
// ============================================================================

#ifndef ACE_SV_SHARED_MEMORY_H
#define ACE_SV_SHARED_MEMORY_H
#include "ace/pre.h"

#include "ace/ACE.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

class ACE_Export ACE_SV_Shared_Memory
{
  // = TITLE
  //     This is a wrapper for System V shared memory.
public:
  enum
  {
    ACE_CREATE = IPC_CREAT,
    ACE_OPEN   = 0
  };

  // = Initialization and termination methods.
  ACE_SV_Shared_Memory (void);
  ACE_SV_Shared_Memory (key_t external_id,
                        size_t size,
                        int create,
                        int perms = ACE_DEFAULT_FILE_PERMS,
                        void *virtual_addr = 0,
                        int flags = 0);

  ACE_SV_Shared_Memory (ACE_HANDLE internal_id,
                        int flags = 0);

  int  open (key_t external_id,
             size_t size,
             int create = ACE_SV_Shared_Memory::ACE_OPEN,
             int perms = ACE_DEFAULT_FILE_PERMS);

  int  open_and_attach (key_t external_id,
                        size_t size,
                        int create = ACE_SV_Shared_Memory::ACE_OPEN,
                        int perms = ACE_DEFAULT_FILE_PERMS,
                        void *virtual_addr = 0,
                        int flags = 0);

  int  attach (void *virtual_addr = 0,
               int flags =0);
  // Attach this shared memory segment.

  int  detach (void);
  // Detach this shared memory segment.

  int  remove (void);
  // Remove this shared memory segment.

  int  control (int cmd, void *buf);
  // Forward to underlying System V <shmctl>.

  // = Segment-related info.
  void *get_segment_ptr (void) const;
  int  get_segment_size (void) const;

  ACE_HANDLE get_id (void) const;
  // Return the ID of the shared memory segment (i.e., an ACE_HANDLE).

  void dump (void) const;
  // Dump the state of an object.

  ACE_ALLOC_HOOK_DECLARE;
  // Declare the dynamic allocation hooks.

protected:
  enum
  {
    ALIGN_WORDB = 8   // Most restrictive alignment.
  };

  ACE_HANDLE internal_id_;
  // Internal identifier.

  int size_;
  // Size of the mapped segment.

  void *segment_ptr_;
  // Pointer to the beginning of the segment.

  int round_up (size_t len);
  // Round up to an appropriate page size.
};

#if defined (__ACE_INLINE__)
#include "ace/SV_Shared_Memory.i"
#endif /* __ACE_INLINE__ */

#include "ace/post.h"
#endif /* ACE_SV_SHARED_MEMORY_H */