// ctors and dtor InitServer::InitServer(int maxstartups): Server(), services_(), pid2services_(), pids_(), registered_services_(0), maxstartups_(maxstartups) { MustBeTrue(maxstartups_ > 0); setOk(true); }
// ctor and dtor Thread::Thread(Task *ptask): UCBaseObject(), handle_(nextHandle()), ptask_(ptask) { MustBeTrue(ptask_ != NULL); ::pthread_attr_init(&state_.attr_); setOk(true); }
int32 Params::init(uint32 max_param_no, uint32 max_param_sz) { int32 ret = 0; // initialize command name buffer ret = m_dbCmdName.init(32); if (ret == FAILURE) return FAILURE; // zeroize command name buffer m_dbCmdName.set(0); // allocate memory for parameters m_strParam = (char * *) malloc(max_param_no * sizeof(char *)); if (!m_strParam) return FAILURE; for (uint32 i = 0; i < max_param_no; i++) { m_strParam[i] = (char *) malloc(max_param_sz); if (!m_strParam[i]) return FAILURE; memset(m_strParam[i], 0, max_param_sz); } m_uParamsFound = 0; m_uMaxParamsNo = max_param_no; m_uMaxParamSize = max_param_sz; // ok setOk(true); return SUCCESS; }
Poisson::Poisson(double lambda, const Random &rng): BaseObject(false), lambda_(lambda), a_(0), rng_(rng) { a_ = exp(-lambda); setOk(true); }
// ctors and dtor Timer::Timer(): BaseObject(false), usertag_(InvalidTag), tag_(InvalidTag), type_(OneShotTimer), seconds_(0), microseconds_(0), userseconds_(0), usermicroseconds_(0) { tag_ = nextTag(); setOk(false); }
int Thread::run() { if (isNotOk() || isStarted()) return(-1); state_.started_ = true; int status = ::pthread_create(&state_.id_, &state_.attr_, execute, this); ThreadMutexLock lock(state_.cs_); setOk(status == 0); return(status); }
int Thread::cancel() { if (isNotOk() || !isStarted() || isDetached()) return(-1); if (isCanceled()) return(0); int status = ::pthread_cancel(state_.id_); ThreadMutexLock lock(state_.cs_); state_.canceled_ = true; setOk(status == 0); return(status); }
Timer::Timer(Seconds s, MicroSeconds us, Tag t, Type y): BaseObject(true), usertag_(t), tag_(InvalidTag), type_(y), seconds_(s+us/1000000), microseconds_(us%1000000), userseconds_(0), usermicroseconds_(0) { userseconds_ = seconds_; usermicroseconds_ = microseconds_; tag_ = nextTag(); setOk(true); }
Timer::Timer(const timeval &tv, Tag t, Type y): BaseObject(true), usertag_(t), tag_(InvalidTag), type_(y), seconds_(tv.tv_sec+tv.tv_usec/1000000), microseconds_(tv.tv_usec%1000000), userseconds_(0), usermicroseconds_(0) { userseconds_ = seconds_; usermicroseconds_ = microseconds_; tag_ = nextTag(); setOk(true); }
int Thread::join(void *&retval) { if (isNotOk() || !isStarted() || isDetached()) return(-1); if (isJoined()) return(0); retval = NULL; int status = ::pthread_join(state_.id_, &retval); ThreadMutexLock lock(state_.cs_); state_.joined_ = true; setOk(status == 0); return(status); }
UserLicenceKey::UserLicenceKey( uint32 id ) : UserElement( UserConstants::TYPE_LICENCE_KEY ), m_licenceKey( NULL ), m_licenceLength( 0 ) { setOk( true ); m_id = id; for ( uint8 i = 0; i < UserConstants::USER_LICENCE_KEY_NBRFIELDS ; i++ ) { m_changed[ i ] = false; } }
UserRight::UserRight( uint32 id ) : UserElement( UserConstants::TYPE_RIGHT ), m_addTime( 0 ), m_userRightType(), m_regionID( MAX_INT32 ), m_startTime( 0 ), m_endTime( MAX_INT32 ), m_deleted( false ), m_origin( "" ) { m_id = id; setOk( true ); for ( uint8 i = 0; i < UserConstants::USER_RIGHT_NBRFIELDS ; i++ ) { m_changed[ i ] = false; } }
int32 Queue::init(char* name, uint32 max_item_size, int32 capacity) { int32 ret = 0; ret = _name.init(name); if (ret == FAILURE) return FAILURE; _item_size = max_item_size; _capacity = capacity; setOk(true); return SUCCESS; }
void UserRight::readFromPacket( const Packet* p, int& pos ) { uint32 type = p->incReadLong( pos ); if ( type == UserConstants::TYPE_RIGHT ) { uint32 size = p->incReadShort( pos ); if ( (getSize() - 6) <= size ) { m_id = p->incReadLong( pos ); m_addTime = p->incReadLong( pos ); m_userRightType.setLevel( UserEnums::userRightLevel( p->incReadLong( pos ) ) ); m_userRightType.setService( UserEnums::userRightService( p->incReadLong( pos ) ) ); m_regionID = p->incReadLong( pos ); m_startTime = p->incReadLong( pos ); m_endTime = p->incReadLong( pos ); m_deleted = p->incReadByte( pos ); m_origin = p->incReadString( pos ); type = p->incReadLong( pos ); if ( type != UserConstants::TYPE_RIGHT ) { mc2log << warn << "UserRight::readFromPacket( " << "Packet* p, int& pos )" << "Data not ended by TYPE_RIGHT!!!" << endl; return; } // DONE } else { mc2log << warn << "UserRight::readFromPacket(Packet* p, int& pos)" << " Not size for data!! Nothing read" << endl; return; } } else { mc2log << warn << "UserRight::readFromPacket( Packet* p, int& pos )" << "Not TYPE_RIGHT_KEY type!!!!!" << endl; return; } setOk( true ); for ( uint8 i = 0; i < UserConstants::USER_RIGHT_NBRFIELDS ; i++ ) { m_changed[ i ] = false; } }
UserRight::UserRight( uint32 id, uint32 addTime, UserEnums::URType type, uint32 regionID, uint32 startTime, uint32 endTime, bool deleted, const char* origin ) : UserElement( UserConstants::TYPE_RIGHT ), m_addTime( addTime ), m_userRightType( type ), m_regionID( regionID ), m_startTime( startTime ), m_endTime( endTime ), m_deleted( deleted ), m_origin( origin ) { m_id = id; setOk( true ); for ( uint8 i = 0; i < UserConstants::USER_RIGHT_NBRFIELDS ; i++ ) { m_changed[ i ] = false; } }
UserLicenceKey::UserLicenceKey( uint32 id, const MC2String& licenceKey, const MC2String& product, const MC2String& keyType ) : UserElement( UserConstants::TYPE_LICENCE_KEY ), m_licenceKey( NULL ), m_licenceLength( 0 ), m_product( product ), m_keyType( keyType ) { m_id = id; setLicence( licenceKey ); //will set some indexes of m_changed to true setOk( true ); for( uint8 i = 0; i < UserConstants::USER_LICENCE_KEY_NBRFIELDS ; ++i){ m_changed[ i ] = false; } }
int32 Command::init(char* name, // command name uint32 min_pc, // minimum acceptable parameters count uint32 max_pc, // maximum acceptable parameters count void* context // generic user data pointer ) { int32 ret = 0; // initialize parent ret = CallBack::init(name); if (ret == FAILURE) return FAILURE; // initialize members m_bEnabled = true; m_uMinParamsCount = min_pc; m_uMaxParamsCount = max_pc; m_voidCtx = context; // initialize string buffers ret = m_dbSyntax.init(32); if (ret == FAILURE) return FAILURE; ret = m_dbDesc.init(32); if (ret == FAILURE) return FAILURE; ret = m_dbWork.init(32); if (ret == FAILURE) return FAILURE; // initialize buffers m_dbSyntax.set(0); m_dbSyntax.setCount(0); m_dbDesc.set(0); m_dbDesc.setCount(0); m_dbWork.set(0); m_dbWork.setCount(0); // ok setOk(true); return SUCCESS; }
int32 SharedHash::init(uint32 hash_size) { int32 ret = 0; // initialize parent ret = Hash::init(hash_size); if (ret == FAILURE) return FAILURE; // initilize mutex ret = _mutex.init(); if (ret == FAILURE) return FAILURE; // ok setOk(true); return SUCCESS; }
int32 Hash::init(uint32 size) { uint32 i, chain_depth = 8; int32 ret = 0; ret = _dbErrorString.init(16); if (ret == FAILURE) return FAILURE; _hte = (struct hash_elem_t *) malloc(sizeof(struct hash_elem_t) * size); if (!_hte) return FAILURE; // DEBUG UOSUTIL_DOUT(("Hash(): init(%u)\n", size)); _size = size; _elem_count = 0; _bytes = 0; ret = _enKeys.init(size * chain_depth); if (ret == FAILURE) return FAILURE; ret = _enValues.init(size * chain_depth); if (ret == FAILURE) return FAILURE; for (i = 0; i < _size; i++) { _hte[i].empty = true; _hte[i].key = NULL; _hte[i].key_size = 0; _hte[i].value = NULL; _hte[i].pvalue = NULL; _hte[i].value_size = 0; _hte[i].next = NULL; _hte[i].hit_count = 0; } setOk(true); return SUCCESS; }
Thread::~Thread() { ThreadMutexLock lock(state_.cs_); if (isOk() && isStarted() && !isDetached()) { void *retval = NULL; if (!isCanceled()) { state_.canceled_ = true; ::pthread_cancel(state_.id_); } if (!isJoined()) { state_.joined_ = true; ::pthread_join(state_.id_, &retval); } } ::pthread_attr_destroy(&state_.attr_); setOk(false); }
UserLicenceKey::UserLicenceKey( uint32 id, const byte* licenceKey, uint32 licenceLength, const MC2String& product, const MC2String& keyType ) : UserElement( UserConstants::TYPE_LICENCE_KEY ), m_licenceKey( NULL ), m_licenceLength( licenceLength ), m_product( product ), m_keyType( keyType ) { m_licenceKey = new byte[ m_licenceLength ]; memcpy( m_licenceKey, licenceKey, m_licenceLength ); m_id = id; setOk( true ); for ( uint8 i = 0; i < UserConstants::USER_LICENCE_KEY_NBRFIELDS ; i++ ) { m_changed[ i ] = false; } }
Timer::~Timer() { setOk(false); }
Geometric::~Geometric() { setOk(false); }
int32 BufferPool::init(char* name, uint32 bsize, uint32 bcount, uint32 limit) { int32 ret = 0; // do some checks if (!bsize) bsize = 1; if (!bcount) bcount = 1; // initialize buffers count _bcount = bcount; // initialize buffer pool's name buffer ret = _dbName.init(name); if (ret == FAILURE) return FAILURE; // create buffers array _bufs = new DataBuf * [bcount]; if (!_bufs) return FAILURE; // initialize buffer ids stack ret = _psFree.init(bcount); if (ret == FAILURE) return FAILURE; // initialize semaphores ret = _semFree.init(bcount); if (ret == FAILURE) return FAILURE; ret = _semUsed.init(0); if (ret == FAILURE) return FAILURE; // initialize mutex for reset ret = _mutexReset.init(); if (ret == FAILURE) return FAILURE; // allocate each buffer for (uint32 i = 0; i < bcount; i++) { // create databuf _bufs[i] = new DataBuf(); // initialize databuf ret = _bufs[i]->init(bsize, i, limit, DataBuf::ALLOC_ONUSE, this); if (ret == FAILURE) return FAILURE; // push buffer pointer into the "free buffers" stack _psFree.push(_bufs[i]); } // ok setOk(true); return SUCCESS; }
UserLicenceKey::UserLicenceKey( const Packet* p, int& pos ) : UserElement( UserConstants::TYPE_LICENCE_KEY ) { uint32 type = p->incReadLong( pos ); m_licenceKey = NULL; m_licenceLength = 0; if ( type == UserConstants::TYPE_LICENCE_KEY ) { uint32 size = p->incReadShort( pos ); if ( 6 + 8 < size ) { m_id = p->incReadLong( pos ); m_licenceLength = p->incReadShort( pos ); uint32 productLength = p->incReadShort( pos ); uint32 keyTypeLength = p->incReadShort( pos ); if ( 8 + m_licenceLength < size && pos + m_licenceLength + productLength + keyTypeLength <= p->getLength() ) { m_licenceKey = new byte[ m_licenceLength ]; memcpy( m_licenceKey, p->getBuf() + pos, m_licenceLength ); // Update pos pos += m_licenceLength; m_product = p->incReadString( pos ); m_keyType = p->incReadString( pos ); type = p->incReadLong( pos ); if ( type != UserConstants::TYPE_LICENCE_KEY ) { mc2log << warn << "UserLicenceKey::UserLicenceKey( p, pos ) " << "Data not ended by TYPE_LICENCE_KEY!!!" << endl; return; } // DONE } else { m_licenceLength = 0; mc2log << warn << "UserLicenceKey::UserLicenceKey(UserReplyPacket* p, pos)" << " Not space for licenceKey!!" << endl; return; } // DONE } else { mc2log << warn << "UserLicenceKey::UserLicenceKey(UserReplyPacket* p,pos)" << " Not size for data!! Nothing read" << endl; return; } } else { mc2log << warn << "UserLicenceKey::UserLicenceKey( UserReplyPacket* p, pos )" << "Not TYPE_LICENCE_KEY type!!!!!" << endl; return; } setOk( true ); for ( uint8 i = 0; i < UserConstants::USER_LICENCE_KEY_NBRFIELDS ; i++ ) { m_changed[ i ] = false; } }
InitServer::~InitServer() { setOk(false); }
// ctors and dtor OldTimer::OldTimer(): BaseObject(false), tag_(InvalidTag), type_(OneShotTimer), seconds_(0), microseconds_(0) { setOk(false); }
OldTimer::OldTimer(Seconds s, MicroSeconds us, Tag t, Type y): BaseObject(true), seconds_(s), microseconds_(us), tag_(t), type_(y) { setOk(true); }
Geometric::Geometric(double p, const Random &rng): BaseObject(false), p_(p), rng_(rng) { setOk(true); }
OldTimer::~OldTimer() { setOk(false); }