| 1 | /********************************************************************** |
|---|
| 2 | * Copyright (c) 2005-2008 David Carter <dcarter@arm4.org> and others. |
|---|
| 3 | * All rights reserved. This program and the accompanying materials |
|---|
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
|---|
| 5 | * which accompanies this distribution, and is available at |
|---|
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
|---|
| 7 | * |
|---|
| 8 | * Contributors: |
|---|
| 9 | * David Carter - Initial API and implementation |
|---|
| 10 | **********************************************************************/ |
|---|
| 11 | |
|---|
| 12 | #ifndef ARM4DBSHAREDMEMORY_H |
|---|
| 13 | #define ARM4DBSHAREDMEMORY_H 1 |
|---|
| 14 | |
|---|
| 15 | #include "arm4_shm.h" |
|---|
| 16 | |
|---|
| 17 | typedef struct arm4_shm_stats { |
|---|
| 18 | unsigned long mq_n_messages; |
|---|
| 19 | unsigned long mq_n_bytes; |
|---|
| 20 | unsigned long mq_max_bytes; |
|---|
| 21 | } arm4_shm_stats_t; |
|---|
| 22 | |
|---|
| 23 | class Arm4dbSharedMemory { |
|---|
| 24 | |
|---|
| 25 | public: |
|---|
| 26 | // Constructors |
|---|
| 27 | Arm4dbSharedMemory (); |
|---|
| 28 | |
|---|
| 29 | // Destructors |
|---|
| 30 | virtual ~Arm4dbSharedMemory (); |
|---|
| 31 | |
|---|
| 32 | // Accessors |
|---|
| 33 | |
|---|
| 34 | // Mutators |
|---|
| 35 | |
|---|
| 36 | // Operations |
|---|
| 37 | static arm4_shm_header_t *shmAttach (void); |
|---|
| 38 | |
|---|
| 39 | static arm_boolean_t setNullCollector (arm_boolean_t set_as_null); |
|---|
| 40 | static arm_boolean_t getNullCollector (void); |
|---|
| 41 | |
|---|
| 42 | // Utility commands |
|---|
| 43 | static void setDebugLevel (int level); |
|---|
| 44 | static void setTransactionTraceInformation (const arm_id_t &tran_id, const arm4db_transaction_summary_t &summary); |
|---|
| 45 | static void setNewTransactionTraceInformation (int index); |
|---|
| 46 | |
|---|
| 47 | // Operators |
|---|
| 48 | |
|---|
| 49 | protected: |
|---|
| 50 | static void lock_transaction (void); |
|---|
| 51 | static void unlock_transaction (void); |
|---|
| 52 | |
|---|
| 53 | static arm4_shm_header_t *g_shared_memory_ptr; |
|---|
| 54 | static int g_message_queue; |
|---|
| 55 | static int g_umask; |
|---|
| 56 | |
|---|
| 57 | static pthread_once_t g_attached; |
|---|
| 58 | |
|---|
| 59 | // This is a library local lock |
|---|
| 60 | static pthread_rwlock_t g_db_rw_lock; |
|---|
| 61 | |
|---|
| 62 | #ifndef USE_POSIX_PROCESS_SEM |
|---|
| 63 | static sem_t *g_sequence_sem_ptr; |
|---|
| 64 | static sem_t *g_application_sem_ptr; |
|---|
| 65 | static sem_t *g_transaction_sem_ptr; |
|---|
| 66 | static sem_t *g_metric_sem_ptr; |
|---|
| 67 | static sem_t *g_utility_sem_ptr; |
|---|
| 68 | |
|---|
| 69 | static const char *instanceName (const char *template_ptr); |
|---|
| 70 | #endif /* USE_POSIX_PROCESS_SEM */ |
|---|
| 71 | |
|---|
| 72 | private: |
|---|
| 73 | |
|---|
| 74 | static void attach_semaphores (void); |
|---|
| 75 | static void doDetach (void); |
|---|
| 76 | static void doAttach (void); |
|---|
| 77 | }; |
|---|
| 78 | |
|---|
| 79 | class Arm4dbLock : |
|---|
| 80 | private Arm4dbSharedMemory |
|---|
| 81 | { |
|---|
| 82 | public: |
|---|
| 83 | // Constructor |
|---|
| 84 | Arm4dbLock (); |
|---|
| 85 | |
|---|
| 86 | // Destructor |
|---|
| 87 | virtual ~Arm4dbLock (); |
|---|
| 88 | |
|---|
| 89 | // Accessors |
|---|
| 90 | |
|---|
| 91 | // Mutators |
|---|
| 92 | |
|---|
| 93 | // Operations |
|---|
| 94 | void lock (void); |
|---|
| 95 | void unlock (void); |
|---|
| 96 | |
|---|
| 97 | // Operators |
|---|
| 98 | |
|---|
| 99 | private: |
|---|
| 100 | bool m_locked; |
|---|
| 101 | }; |
|---|
| 102 | |
|---|
| 103 | class Arm4dbWriteLock : |
|---|
| 104 | private Arm4dbSharedMemory |
|---|
| 105 | { |
|---|
| 106 | public: |
|---|
| 107 | // Constructor |
|---|
| 108 | Arm4dbWriteLock (); |
|---|
| 109 | |
|---|
| 110 | // Destructor |
|---|
| 111 | virtual ~Arm4dbWriteLock (); |
|---|
| 112 | |
|---|
| 113 | // Accessors |
|---|
| 114 | |
|---|
| 115 | // Mutators |
|---|
| 116 | |
|---|
| 117 | // Operations |
|---|
| 118 | void lock (void); |
|---|
| 119 | void unlock (void); |
|---|
| 120 | |
|---|
| 121 | // Operators |
|---|
| 122 | |
|---|
| 123 | private: |
|---|
| 124 | bool m_locked; |
|---|
| 125 | }; |
|---|
| 126 | |
|---|
| 127 | class Arm4dbUtilityLock : |
|---|
| 128 | private Arm4dbSharedMemory |
|---|
| 129 | { |
|---|
| 130 | public: |
|---|
| 131 | // Constructor |
|---|
| 132 | Arm4dbUtilityLock (); |
|---|
| 133 | |
|---|
| 134 | // Destructor |
|---|
| 135 | virtual ~Arm4dbUtilityLock (); |
|---|
| 136 | |
|---|
| 137 | // Accessors |
|---|
| 138 | |
|---|
| 139 | // Mutators |
|---|
| 140 | |
|---|
| 141 | // Operations |
|---|
| 142 | void lock (void); |
|---|
| 143 | void unlock (void); |
|---|
| 144 | |
|---|
| 145 | // Operators |
|---|
| 146 | |
|---|
| 147 | private: |
|---|
| 148 | bool m_locked; |
|---|
| 149 | }; |
|---|
| 150 | |
|---|
| 151 | #endif /* ARM4DBSHAREDMEMORY_H */ |
|---|