Example #1
0
void WalletLegacy::initAndGenerateOrRecover
	(
		const std::string& password, 
		const Crypto::SecretKey& recovery_key,
		const Crypto::SecretKey& secondary_key,
		bool is_recovery, 
		bool is_copy, 
		bool is_deterministic
	) 
{

  {
    std::unique_lock<std::mutex> stateLock(m_cacheMutex);

    if (m_state != NOT_INITIALIZED) {
      throw std::system_error(make_error_code(error::ALREADY_INITIALIZED));
    }

    m_account.generate_or_recover(recovery_key, secondary_key, is_recovery, is_copy, is_deterministic);
    m_password = password;

    initSync();
  }

  m_observerManager.notify(&IWalletLegacyObserver::initCompleted, std::error_code());
}
Example #2
0
void* VRDeviceClient::streamReceiveThreadMethod(void)
	{
	while(true)
		{
		/* Wait for next packet reply message: */
		VRDevicePipe::MessageIdType message=pipe.readMessage();
		if(message==VRDevicePipe::PACKET_REPLY)
			{
			/* Read server's state: */
			{
			Threads::Mutex::Lock stateLock(stateMutex);
			state.read(pipe);
			}
			
			/* Signal packet reception: */
			packetSignalCond.broadcast();
			
			/* Invoke packet notification callback: */
			{
			Threads::Mutex::Lock packetNotificationLock(packetNotificationMutex);
			if(packetNotificationCB!=0)
				packetNotificationCB(this,packetNotificationCBData);
			}
			}
		else if(message==VRDevicePipe::STOPSTREAM_REPLY)
			break;
		else
			throw ProtocolError("VRDeviceClient: Mismatching message while waiting for PACKET_REPLY");
		}
	
	return 0;
	}
void VRDeviceManager::enableTrackerUpdateNotification(Threads::MutexCond* sTrackerUpdateCompleteCond)
	{
	Threads::Mutex::Lock stateLock(stateMutex);
	trackerUpdateNotificationEnabled=true;
	trackerUpdateCompleteCond=sTrackerUpdateCompleteCond;
	trackerReportMask=0x0;
	}
Example #4
0
void VRDeviceClient::getPacket(void)
	{
	if(active)
		{
		if(streaming)
			{
			/* Wait for arrival of next packet: */
			packetSignalCond.wait();
			}
		else
			{
			/* Send packet request message: */
			pipe.writeMessage(VRDevicePipe::PACKET_REQUEST);
			pipe.flush();
			
			/* Wait for packet reply message: */
			pipe.waitForData(10,0); // Throw exception if reply does not arrive in time
			if(pipe.readMessage()!=VRDevicePipe::PACKET_REPLY)
				throw ProtocolError("VRDeviceClient: Mismatching message while waiting for PACKET_REPLY");
			
			/* Read server's state: */
			{
			Threads::Mutex::Lock stateLock(stateMutex);
			state.read(pipe);
			}
			
			/* Invoke packet notification callback: */
			{
			Threads::Mutex::Lock packetNotificationLock(packetNotificationMutex);
			if(packetNotificationCB!=0)
				packetNotificationCB(this,packetNotificationCBData);
			}
			}
		}
	}
Example #5
0
int indri::collection::Repository::addDocument(indri::api::ParsedDocument* document, bool inCollection) {
  if (_readOnly)
    LEMUR_THROW(LEMUR_RUNTIME_ERROR, "addDocument: Cannot add documents to a repository that is opened for read-only access."); 

  while (_thrashing) {
    indri::thread::Thread::sleep(100);
  }

  indri::thread::ScopedLock lock(_addLock);

  for(size_t i=0; i<_transformations.size(); i++) {
    document = _transformations[i]->transform(document);
  }

  index_state state;

  { 
    // get a copy of current index state
    indri::thread::ScopedLock stateLock(_stateLock);
    state = _active;
  }

  int documentID = dynamic_cast<indri::index::MemoryIndex*>(state->back())->addDocument(*document);
  if (inCollection) _collection->addDocument(documentID, document);

  _countDocumentAdd();
  return documentID;
}
Example #6
0
void VRPNClient::stop(void)
	{
	/* Stop reporting events to the device manager: */
	{
	Threads::Mutex::Lock stateLock(stateMutex);
	reportEvents=false;
	}
	}
void VRDeviceManager::updateState(void)
	{
	Threads::Mutex::Lock stateLock(stateMutex);
	if(trackerUpdateNotificationEnabled)
		{
		/* Wake up all client threads in stream mode: */
		trackerUpdateCompleteCond->broadcast();
		}
	}
Example #8
0
Joystick::~Joystick(void)
{
    /* Stop device thread (joystick device cannot be disabled): */
    {
        Threads::Mutex::Lock stateLock(stateMutex);
        stopDeviceThread();
    }
    delete[] buttonStates;
    delete[] valuatorStates;
    delete[] axisGains;
    close(joystickDeviceFd);
}
Example #9
0
VRPNClient::~VRPNClient(void)
	{
	/* Stop device communication thread: */
	{
	Threads::Mutex::Lock stateLock(stateMutex);
	stopDeviceThread();
	}
	
	delete[] trackerStates;
	delete[] buttonStates;
	delete[] valuatorStates;
	}
Example #10
0
void WalletLegacy::initAndLoad(std::istream& source, const std::string& password) {
  std::unique_lock<std::mutex> stateLock(m_cacheMutex);

  if (m_state != NOT_INITIALIZED) {
    throw std::system_error(make_error_code(error::ALREADY_INITIALIZED));
  }

  m_password = password;
  m_state = LOADING;
      
  m_asyncContextCounter.addAsyncContext();
  std::thread loader(&WalletLegacy::doLoad, this, std::ref(source));
  loader.detach();
}
Example #11
0
void HIDDevice::start(void)
	{
	/* Set device manager's button and valuator states to current states: */
	{
	Threads::Mutex::Lock stateLock(stateMutex);
	for(int i=0;i<getNumButtons();++i)
		setButtonState(i,buttonStates[i]);
	for(int i=0;i<getNumValuators();++i)
		setValuatorState(i,valuatorStates[i]);
	
	/* Start reporting events to the device manager: */
	reportEvents=true;
	}
	}
Example #12
0
void Wallet::initAndLoad(std::istream& source, const std::string& password) {
  std::unique_lock<std::mutex> stateLock(m_cacheMutex);

  if (m_state != NOT_INITIALIZED) {
    throw std::system_error(make_error_code(cryptonote::error::NOT_INITIALIZED));
  }

  m_node.addObserver(m_autoRefresher.get());

  m_password = password;
  m_state = LOADING;

  std::thread loader(&Wallet::doLoad, this, std::ref(source));
  loader.detach();
}
Example #13
0
    void ICharacter::consumeHP (const uint32_t amount)
    {
        if (amount)
        {
            boost::mutex::scoped_lock stats_lock(m_stats_mutex);

            if (m_HP)
            {
                if ( amount > m_HP)
                    m_HP = 0;
                else
                    m_HP -= amount;

                if (!m_HP)
                {
                    stats_lock.unlock();

                    if (!signal_dead.empty())
                        signal_dead(m_UniqueID,m_CurrentPos);

                    boost::lock(m_state_mutex,m_queue_mutex,m_mov_mutex);

                    boost::unique_lock<boost::mutex> stateLock(m_state_mutex,boost::adopt_lock);
                    boost::unique_lock<boost::mutex> queueLock(m_queue_mutex,boost::adopt_lock);
                    boost::unique_lock<boost::mutex> moveLock(m_mov_mutex,boost::adopt_lock);

                    if (m_AttackState != ATTACK_ACTION_STOP)
                    {
                        m_AttackState = ATTACK_ACTION_STOP;

                        if (!signal_state.empty())
                            signal_state(STATE_ATTACK,m_AttackState);
                    }

                    m_StatusState = STATUS_ACTION_DEAD;

                    if (!signal_state.empty())
                        signal_state(STATE_STATUS,m_StatusState);

                    m_QueueSkill = 0;
                    m_QueueTarget = 0;
                    m_CurrentTask = 0;

                    m_NextPos = Coord();
                }
            }
        }
    }
Example #14
0
void WalletLegacy::initAndGenerate(const std::string& password) {
  {
    std::unique_lock<std::mutex> stateLock(m_cacheMutex);

    if (m_state != NOT_INITIALIZED) {
      throw std::system_error(make_error_code(error::ALREADY_INITIALIZED));
    }

    m_account.generate();
    m_password = password;

    initSync();
  }

  m_observerManager.notify(&IWalletLegacyObserver::initCompleted, std::error_code());
}
Example #15
0
HIDDevice::~HIDDevice(void)
	{
	/* Stop device thread (HID device cannot be disabled): */
	{
	Threads::Mutex::Lock stateLock(stateMutex);
	stopDeviceThread();
	}
	delete[] buttonStates;
	delete[] valuatorStates;
	delete[] keyMap;
	delete[] absAxisMap;
	delete[] relAxisMap;
	delete[] axisConverters;
	if(deviceFd>=0)
		close(deviceFd);
	}
Example #16
0
void WalletLegacy::initWithKeys(const AccountKeys& accountKeys, const std::string& password) {
  {
    std::unique_lock<std::mutex> stateLock(m_cacheMutex);

    if (m_state != NOT_INITIALIZED) {
      throw std::system_error(make_error_code(error::ALREADY_INITIALIZED));
    }

    m_account.setAccountKeys(accountKeys);
    m_account.set_createtime(ACCOUN_CREATE_TIME_ACCURACY);
    m_password = password;

    initSync();
  }

  m_observerManager.notify(&IWalletLegacyObserver::initCompleted, std::error_code());
}
void VRDeviceManager::setTrackerState(int trackerIndex,const Vrui::VRDeviceState::TrackerState& newTrackerState,Vrui::VRDeviceState::TimeStamp newTimeStamp)
	{
	Threads::Mutex::Lock stateLock(stateMutex);
	state.setTrackerState(trackerIndex,newTrackerState);
	state.setTrackerTimeStamp(trackerIndex,newTimeStamp);
	
	if(trackerUpdateNotificationEnabled)
		{
		/* Update tracker report mask: */
		trackerReportMask|=1<<trackerIndex;
		if(trackerReportMask==fullTrackerReportMask)
			{
			/* Wake up all client threads in stream mode: */
			trackerUpdateCompleteCond->broadcast();
			trackerReportMask=0x0;
			}
		}
	}
Example #18
0
void Joystick::deviceThreadMethod(void)
{
    while(true)
    {
        /* Try reading a bunch of joystick events: */
        struct js_event joyEvents[32];
        int numEvents=read(joystickDeviceFd,joyEvents,32*sizeof(struct js_event));

        /* Process all reported joystick events: */
        if(numEvents>0)
        {
            {
                Threads::Mutex::Lock stateLock(stateMutex);
                numEvents/=sizeof(struct js_event);
                for(int i=0; i<numEvents; ++i)
                {
                    switch(joyEvents[i].type&~JS_EVENT_INIT)
                    {
                    case JS_EVENT_BUTTON:
                    {
                        int buttonIndex=joyEvents[i].number;
                        bool newButtonState=joyEvents[i].value;
                        if(newButtonState!=buttonStates[buttonIndex]&&reportEvents)
                            setButtonState(buttonIndex,newButtonState);
                        buttonStates[buttonIndex]=newButtonState;
                        break;
                    }

                    case JS_EVENT_AXIS:
                    {
                        int valuatorIndex=joyEvents[i].number;
                        float newValuatorState=float(joyEvents[i].value)/32767.0f;
                        newValuatorState=Math::pow(newValuatorState,axisGains[valuatorIndex]);
                        if(newValuatorState!=valuatorStates[valuatorIndex]&&reportEvents)
                            setValuatorState(valuatorIndex,newValuatorState);
                        valuatorStates[valuatorIndex]=newValuatorState;
                        break;
                    }
                    }
                }
            }
        }
    }
}
Example #19
0
void neo::LuaContext::executeCode(std::istream& code) {
	std::lock_guard<std::mutex> stateLock(_stateMutex);

	// since the lua_load function requires a static function, we use this structure
	// the Reader structure is at the same time an object storing an istream and a buffer,
	//   and a static function provider
	struct Reader {
		Reader(std::istream& str) : stream(str) {}
		std::istream&		stream;
		char				buffer[512];

		// read function ; "data" must be an instance of Reader
		static const char* read(lua_State* l, void* data, size_t* size) {
			assert(size != nullptr);
			assert(data != nullptr);
			Reader& me = *((Reader*)data);
			if (me.stream.eof())	{ *size = 0; return nullptr; }

			me.stream.read(me.buffer, sizeof(me.buffer));
			*size = size_t(me.stream.gcount());		// gcount could return a value larger than a size_t, but its maximum is sizeof(me.buffer) so there's no problem
			return me.buffer;
		}
	};

	// we create an instance of Reader, and we call lua_load
	std::unique_ptr<Reader> reader(new Reader(code));
	auto loadReturnValue = lua_load(_state, &Reader::read, reader.get(), "chunk");

	// now we have to check return value
	if (loadReturnValue != 0) {
		// there was an error during loading, an error message was pushed on the stack
		const char* errorMsg = lua_tostring(_state, -1);
		lua_pop(_state, 1);
		if (loadReturnValue == LUA_ERRMEM)			throw(std::bad_alloc());
		else if (loadReturnValue == LUA_ERRSYNTAX)	throw(SyntaxErrorException(std::string(errorMsg)));

	} else {
		// calling the loaded function
		_call<std::tuple<>>(std::tuple<>());
	}
}
Example #20
0
void Wallet::initAndGenerate(const std::string& password) {
  {
    std::unique_lock<std::mutex> stateLock(m_cacheMutex);

    if (m_state != NOT_INITIALIZED) {
      throw std::system_error(make_error_code(cryptonote::error::NOT_INITIALIZED));
    }

    m_node.addObserver(m_autoRefresher.get());

    m_account.generate();
    m_password = password;

    m_sender.init(m_account.get_keys());

    storeGenesisBlock();

    m_state = INITIALIZED;
  }

  m_observerManager.notify(&IWalletObserver::initCompleted, std::error_code());
  refresh();
}
void VRDeviceManager::setButtonState(int buttonIndex,Vrui::VRDeviceState::ButtonState newButtonState)
	{
	Threads::Mutex::Lock stateLock(stateMutex);
	state.setButtonState(buttonIndex,newButtonState);
	}
void VRDeviceManager::setValuatorState(int valuatorIndex,Vrui::VRDeviceState::ValuatorState newValuatorState)
	{
	Threads::Mutex::Lock stateLock(stateMutex);
	state.setValuatorState(valuatorIndex,newValuatorState);
	}
void VRDeviceManager::disableTrackerUpdateNotification(void)
	{
	Threads::Mutex::Lock stateLock(stateMutex);
	trackerUpdateNotificationEnabled=false;
	trackerUpdateCompleteCond=0;
	}