예제 #1
0
// ctors and dtor
InitServer::InitServer(int maxstartups):
    Server(), services_(), pid2services_(), pids_(), 
    registered_services_(0), maxstartups_(maxstartups)
{
    MustBeTrue(maxstartups_ > 0);
    setOk(true);
}
예제 #2
0
파일: Thread.cpp 프로젝트: ombt/statistics
// ctor and dtor
Thread::Thread(Task *ptask):
    UCBaseObject(), handle_(nextHandle()), ptask_(ptask)
{
    MustBeTrue(ptask_ != NULL);
    ::pthread_attr_init(&state_.attr_);
    setOk(true);
}
예제 #3
0
	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;
	}
예제 #4
0
파일: Poisson.cpp 프로젝트: ombt/statistics
Poisson::Poisson(double lambda, const Random &rng): 
    BaseObject(false), 
    lambda_(lambda), a_(0), rng_(rng)
{
    a_ = exp(-lambda);
    setOk(true);
}
예제 #5
0
파일: Timer.cpp 프로젝트: ombt/statistics
// 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);
}
예제 #6
0
파일: Thread.cpp 프로젝트: ombt/statistics
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);
}
예제 #7
0
파일: Thread.cpp 프로젝트: ombt/statistics
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);
}
예제 #8
0
파일: Timer.cpp 프로젝트: ombt/statistics
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);
}
예제 #9
0
파일: Timer.cpp 프로젝트: ombt/statistics
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);
}
예제 #10
0
파일: Thread.cpp 프로젝트: ombt/statistics
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;
   }
}
예제 #12
0
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;
   }
}
예제 #13
0
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;
}
예제 #14
0
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;
   }
}
예제 #15
0
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;
   }
}
예제 #17
0
	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;
	}
예제 #18
0
	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;
	}
예제 #19
0
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;
}
예제 #20
0
파일: Thread.cpp 프로젝트: ombt/statistics
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;
   }
}
예제 #22
0
파일: Timer.cpp 프로젝트: ombt/statistics
Timer::~Timer()
{
    setOk(false);
}
예제 #23
0
Geometric::~Geometric()
{
    setOk(false);
}
예제 #24
0
	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;
   }
}
예제 #26
0
InitServer::~InitServer()
{
    setOk(false);
}
예제 #27
0
// ctors and dtor
OldTimer::OldTimer(): 
    BaseObject(false), tag_(InvalidTag), type_(OneShotTimer),
    seconds_(0), microseconds_(0)
{
    setOk(false);
}
예제 #28
0
OldTimer::OldTimer(Seconds s, MicroSeconds us, Tag t, Type y): 
    BaseObject(true), seconds_(s), 
    microseconds_(us), tag_(t), type_(y)
{
    setOk(true);
}
예제 #29
0
Geometric::Geometric(double p, const Random &rng): 
    BaseObject(false), p_(p), rng_(rng)
{
    setOk(true);
}
예제 #30
0
OldTimer::~OldTimer()
{
    setOk(false);
}