| 1 |
// $Id: b_ace.h,v 1.5 2003/03/02 04:12:45 fukasawa Exp $ |
| 2 |
|
| 3 |
//============================================================================= |
| 4 |
/** |
| 5 |
* @file b_ace.h |
| 6 |
* |
| 7 |
* @author Fukasawa Mitsuo |
| 8 |
* |
| 9 |
* |
| 10 |
* Copyright (C) 1998-2004 BEE Co.,Ltd. All rights reserved. |
| 11 |
* |
| 12 |
* This program is free software; you can redistribute it and/or |
| 13 |
* modify it under the terms of the GNU General Public License |
| 14 |
* as published by the Free Software Foundation; either version 2 |
| 15 |
* of the License, or (at your option) any later version. |
| 16 |
* |
| 17 |
* This program is distributed in the hope that it will be useful, |
| 18 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 |
* GNU General Public License for more details. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU General Public License |
| 23 |
* along with this program; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 |
*/ |
| 26 |
//============================================================================= |
| 27 |
|
| 28 |
#ifndef B_ACE_H |
| 29 |
#define B_ACE_H |
| 30 |
|
| 31 |
#ifdef _MSC_VER |
| 32 |
#pragma warning(disable: 4786 4284 4018) |
| 33 |
#endif |
| 34 |
|
| 35 |
#include <vector> |
| 36 |
#include <list> |
| 37 |
#include <map> |
| 38 |
#include <stack> |
| 39 |
#include <set> |
| 40 |
#include <string> |
| 41 |
#include <algorithm> |
| 42 |
#include <iostream> |
| 43 |
using namespace std; |
| 44 |
|
| 45 |
#include "ace/Version.h" |
| 46 |
#include "ace/streams.h" |
| 47 |
#include "ace/OS.h" |
| 48 |
#include "ace/ACE.h" |
| 49 |
#include "ace/Log_Msg.h" |
| 50 |
#include "ace/Synch.h" |
| 51 |
#include "ace/Module.h" |
| 52 |
#include "ace/Task.h" |
| 53 |
#include "ace/Reactor.h" |
| 54 |
#include "ace/Proactor.h" |
| 55 |
#include "ace/Singleton.h" |
| 56 |
|
| 57 |
#include "ace/Atomic_Op.h" |
| 58 |
|
| 59 |
#if (ACE_MAJOR_VERSION >= 5) && (ACE_MINOR_VERSION >= 4) |
| 60 |
#include "ace/Trace.h" |
| 61 |
#endif |
| 62 |
|
| 63 |
#define BCHAR ACE_TCHAR |
| 64 |
#define _TX ACE_TEXT |
| 65 |
|
| 66 |
#include "BEE_Export.h" |
| 67 |
#include "beelib.h" |
| 68 |
|
| 69 |
// wrapper macro fot log |
| 70 |
#define ERROR_LOG(x) ACE_ERROR((LM_ERROR, ACE_TEXT(x))) |
| 71 |
#define ERROR_LOG1(x,p1) ACE_ERROR((LM_ERROR, ACE_TEXT(x),p1)) |
| 72 |
#define ERROR_LOG2(x,p1,p2) ACE_ERROR((LM_ERROR, ACE_TEXT(x),p1,p2)) |
| 73 |
#define ERROR_LOG3(x,p1,p2,p3) ACE_ERROR((LM_ERROR, ACE_TEXT(x),p1,p2,p3)) |
| 74 |
#define ERROR_LOG4(x,p1,p2,p3,p4) ACE_ERROR((LM_ERROR, ACE_TEXT(x),p1,p2,p3,p4)) |
| 75 |
#define ERROR_LOG5(x,p1,p2,p3,p4,p5) ACE_ERROR((LM_ERROR, ACE_TEXT(x),p1,p2,p3,p4,p5)) |
| 76 |
|
| 77 |
#define DEBUG_LOG(x) ACE_DEBUG((LM_DEBUG, ACE_TEXT(x))) |
| 78 |
#define DEBUG_LOG1(x,p1) ACE_DEBUG((LM_DEBUG, ACE_TEXT(x),p1)) |
| 79 |
#define DEBUG_LOG2(x,p1,p2) ACE_DEBUG((LM_DEBUG, ACE_TEXT(x),p1,p2)) |
| 80 |
#define DEBUG_LOG3(x,p1,p2,p3) ACE_DEBUG((LM_DEBUG, ACE_TEXT(x),p1,p2,p3)) |
| 81 |
#define DEBUG_LOG4(x,p1,p2,p3,p4) ACE_DEBUG((LM_DEBUG, ACE_TEXT(x),p1,p2,p3,p4)) |
| 82 |
#define DEBUG_LOG5(x,p1,p2,p3,p4,p5) ACE_DEBUG((LM_DEBUG, ACE_TEXT(x),p1,p2,p3,p4,p5)) |
| 83 |
|
| 84 |
// declare any types |
| 85 |
typedef ACE_Module<ACE_MT_SYNCH> MT_Module; |
| 86 |
typedef ACE_Task<ACE_MT_SYNCH> MT_Task; |
| 87 |
typedef ACE_Message_Queue<ACE_MT_SYNCH> MT_Queue; |
| 88 |
|
| 89 |
typedef ACE_Atomic_Op<ACE_Thread_Mutex, unsigned int> MUTEX_UInt; |
| 90 |
typedef ACE_Atomic_Op<ACE_Thread_Mutex, int> MUTEX_Int; |
| 91 |
typedef ACE_Atomic_Op<ACE_Thread_Mutex, bool> MUTEX_Bool; |
| 92 |
typedef ACE_Atomic_Op<ACE_Thread_Mutex, void *> MUTEX_Ptr; |
| 93 |
|
| 94 |
struct int_less |
| 95 |
{ |
| 96 |
bool operator() (int x, int y) const { return (x < y); } |
| 97 |
}; |
| 98 |
|
| 99 |
struct uint_less |
| 100 |
{ |
| 101 |
bool operator() (UINT x, UINT y) const { return (x < y); } |
| 102 |
}; |
| 103 |
|
| 104 |
struct tchar_less |
| 105 |
{ |
| 106 |
bool operator() (TCHAR * x, TCHAR * y) const { return _tcscmp(x, y) < 0; } |
| 107 |
}; |
| 108 |
|
| 109 |
struct str_less |
| 110 |
{ |
| 111 |
bool operator() (string x, string y) const { return (x < y); } |
| 112 |
}; |
| 113 |
|
| 114 |
struct cstr_less |
| 115 |
{ |
| 116 |
bool operator() (const string& x, const string& y) const { return (x < y); } |
| 117 |
}; |
| 118 |
|
| 119 |
struct char_less |
| 120 |
{ |
| 121 |
bool operator() (char * x, char * y) const |
| 122 |
{ return (strcmp(x, y) < 0); } |
| 123 |
}; |
| 124 |
|
| 125 |
struct cchar_less |
| 126 |
{ |
| 127 |
bool operator() (const char * x, const char * y) const |
| 128 |
{ return (strcmp(const_cast<char *>(x), |
| 129 |
const_cast<char *>(y)) < 0); } |
| 130 |
}; |
| 131 |
|
| 132 |
struct nocase_less |
| 133 |
{ |
| 134 |
bool operator() (string x, string y) const |
| 135 |
{ |
| 136 |
string::iterator p = x.begin(); |
| 137 |
string::iterator q = y.begin(); |
| 138 |
while (p != x.end() && q != y.end() && toupper(*p) == toupper(*q)) |
| 139 |
{ |
| 140 |
++p; |
| 141 |
++q; |
| 142 |
} |
| 143 |
if (p == x.end()) |
| 144 |
return (q != y.end()); |
| 145 |
if (q == y.end()) |
| 146 |
return false; |
| 147 |
return (toupper(*p) < toupper(*q)); |
| 148 |
} |
| 149 |
}; |
| 150 |
|
| 151 |
// |
| 152 |
// macro for Mutex Lock |
| 153 |
// |
| 154 |
#define BEE_GUARD_RETURN(MUTEX,OBJ,LOCK,RETURN,COUNT,MSEC) \ |
| 155 |
ACE_Guard< MUTEX > OBJ (LOCK); \ |
| 156 |
int ___##OBJ = COUNT; \ |
| 157 |
while (1) { \ |
| 158 |
if (OBJ.locked() != 0) break; \ |
| 159 |
___##OBJ--; \ |
| 160 |
if (___##OBJ == 0) return RETURN; \ |
| 161 |
ACE_Time_Value __tv##OBJ(0, MSEC * 1000); \ |
| 162 |
ACE_OS::sleep(__tv##OBJ); \ |
| 163 |
} |
| 164 |
|
| 165 |
#define BEE_GUARD_LOOP(MUTEX,OBJ,LOCK) \ |
| 166 |
ACE_Guard< MUTEX > OBJ (LOCK); \ |
| 167 |
while (1) { \ |
| 168 |
if (OBJ.locked() != 0) break; \ |
| 169 |
ACE_Time_Value __tv##OBJ(0, 250 * 1000); \ |
| 170 |
ACE_OS::sleep(__tv##OBJ); \ |
| 171 |
} |
| 172 |
|
| 173 |
// |
| 174 |
// Timer Queue: |
| 175 |
// These typedefs ensure that we use the minimal amount of locking necessary. |
| 176 |
// |
| 177 |
#include "ace/Timer_Queue_Adapters.h" |
| 178 |
|
| 179 |
typedef ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex> Upcall; |
| 180 |
typedef ACE_Timer_Heap_T<ACE_Event_Handler *, Upcall, ACE_Null_Mutex> |
| 181 |
Timer_Heap; |
| 182 |
typedef ACE_Timer_Heap_Iterator_T<ACE_Event_Handler *, Upcall, ACE_Null_Mutex> |
| 183 |
Timer_Heap_Iterator; |
| 184 |
typedef ACE_Thread_Timer_Queue_Adapter<Timer_Heap> Thread_Timer_Queue; |
| 185 |
|
| 186 |
#endif /* B_ACE_H */ |