예제 #1
0
파일: Joystick.cpp 프로젝트: thayamizu/Nyx
	//-----------------------------------------------------------------------------------------
	//
	bool joystick::initialize(const input_device_desc& desc) {
		NYX_ASSERT(pimpl_ != nullptr);
		if (is_initialized()) {
			return is_initialized();
		}		

		pimpl_->initialize((HWND)desc.handle, desc.range, desc.button);

		return pimpl_->isInitialized;
	}
예제 #2
0
파일: Keyboard.cpp 프로젝트: thayamizu/Nyx
	bool keyboard::initialize(const input_device_desc& desc) {
		NYX_ASSERT(pimpl_ != nullptr);
		if (is_initialized()) {
			return is_initialized();
		}		

		pimpl_->initialize((HWND)desc.handle);

		return pimpl_->isInitialized;
	}
예제 #3
0
void ARVRInterface::set_is_initialized(bool p_initialized) {
	if (p_initialized) {
		if (!is_initialized()) {
			initialize();
		};
	} else {
		if (is_initialized()) {
			uninitialize();
		};
	};
};
예제 #4
0
 void push_back(value_type const& item)
 {
     if (!is_initialized(items_[0]))
     {
         items_[0] = item;
     }
     else if (!is_initialized(items_[1]))
     {
         items_[1] = item;
     }
     else
     {
         BOOST_ASSERT(false);
     }
 }
예제 #5
0
파일: Sound.cpp 프로젝트: ziz/solarus
/**
 * @brief Loads and decodes all sounds listed in the game database.
 */
void Sound::load_all() {

  if (is_initialized()) {

    // open the resource database file
    const std::string file_name = "project_db.dat";
    std::istream& database_file = FileTools::data_file_open(file_name);
    std::string line;

    // read each animation
    while (std::getline(database_file, line)) {

      if (line.size() == 0) {
        continue;
      }

      int resource_type;
      std::string resource_id, resource_name;
      std::istringstream iss(line);
      FileTools::read(iss, resource_type);
      FileTools::read(iss, resource_id);
      FileTools::read(iss, resource_name);

      if (resource_type == 4) { // it's a sound

        if (all_sounds.count(resource_id) == 0) {
          all_sounds[resource_id] = Sound(resource_id);
          all_sounds[resource_id].load();
        }
      }
    }
    FileTools::data_file_close(database_file);
  }
}
예제 #6
0
파일: Sound.cpp 프로젝트: ziz/solarus
/**
 * @brief Closes the audio (music and sound) system.
 *
 * This method should be called when exiting the application.
 */
void Sound::quit() {

  if (is_initialized()) {

/*
    // stop the sound sources
    ALuint source;
    std::list<ALuint>::iterator it;
    for (it = all_sources.begin(); it != all_sources.end(); it++) {
      source = (*it);
      alSourcei(source, AL_BUFFER, 0);
      alDeleteSources(1, &source);
    }
*/
    // uninitialize the music subsystem
    Music::quit();

    // clear the sounds
    all_sounds.clear();

    // uninitialize OpenAL

    alcMakeContextCurrent(NULL);
    alcDestroyContext(context);
    context = NULL;
    alcCloseDevice(device);
    device = NULL;

    initialized = false;
  }
}
예제 #7
0
파일: Comm.cpp 프로젝트: Peita/coolfluid3
void Comm::finalize()
{
  if( is_initialized() && !is_finalized() ) // then finalized
  {
    MPI_CHECK_RESULT(MPI_Finalize,());
    //  CFinfo << "MPI (version " <<  version() << ") -- finalized" << CFendl;
  }
예제 #8
0
bool Opl2::generate(
	const int count,
	std::int16_t* buffer)
{
	if (!is_initialized())
	{
		return false;
	}

	if (count < 1)
	{
		return false;
	}

	if (!buffer)
	{
		return false;
	}

	auto remain_count = count;

	while (remain_count > 0)
	{
		const auto generate_count = std::min(remain_count, get_max_samples_count());

		channel_.set_buffer(buffer);

		emulator_.Generate(&channel_, static_cast<Bitu>(generate_count));

		remain_count -= generate_count;
		buffer += generate_count;
	}

	return true;
}
예제 #9
0
matlab_image_t matlab_image_t<T>::operator=(const matlab_engine_t other)
{
  initialized_ = other.initialized_();
  if (is_initialized())
    initialize(other.get_const_array());
  return *this;
}
예제 #10
0
	std::future<std::vector<SpellDataPtr>> SpellData::GetGlobalSpells(
		SpellDataListCallback success, APIFailureCallback failure)
	{
		return std::async(std::launch::async, [=]() -> std::vector<SpellDataPtr> {
			APIRequestManager *manager = APIRequestManager::GetDefaultManager();

			std::stringstream url;
			url << "/spells/1";

			std::string error; 
			auto response = manager->Send(url.str(), "GET", "", error);

			if (response.is_initialized()) {
				TSpellDataList items;
				ParseSpellList(response.get(), items);

				if (success) {
					Dispatch::PushTask(Dispatch::MainQueue, [&items, success]() {
						success(items);
					});
				}

				return items;
			}
			else {
				if (failure) {
					Dispatch::PushTask(Dispatch::MainQueue, [&]() {
						failure(error);
					});
				}

				return std::vector<SpellDataPtr>();
			}
		});
	}
예제 #11
0
void ThreadLocalStorage::init() {
    assert(!is_initialized(),
           "More than one attempt to initialize threadLocalStorage");
    pd_init();
    set_thread_index(os::allocate_thread_local_storage());
    generate_code_for_get_thread();
}
예제 #12
0
 int altix_lock_card(int fd, int id)
{
	int cid = id;
	if(!is_initialized()) return ALTIX_NOT_INITIALIZED;
	if(ioctl(fd, ALTIX_IOCTL_LOCK, &cid) == 0) 
	{
		#ifdef ALTIX_DEBUG
			printf("libaltix: Locked %d \n", id);
		#endif
		return ALTIX_OK;
	}
	if(errno == EBUSY)
	{
		#ifdef ALTIX_DEBUG
			printf("libaltix:Card %d already in use\n", id);
		#endif
		return ALTIX_CARD_BUSY;
	}
	else
	{
		#ifdef ALTIX_DEBUG
			printf("libaltix: Could not find card with id %d\n", id);
		#endif
		return ALTIX_CARD_NOT_VALID;
	}
}
예제 #13
0
void* altix_read_event(int fd, void* buff)
{
	int error;
	int allocated = 0;
	int size = BEAM_TEST_EVENT_SIZE;
	if(!is_initialized()) return 0;
	if(buff == NULL)
	{
		allocated = 1;
		buff = malloc(BEAM_TEST_EVENT_SIZE);
	}
	while(size > 0)
	{
		error = read(fd, (char*)buff + BEAM_TEST_EVENT_SIZE - size, size);
		if(error <0)
		{
			#ifdef ALTIX_DEBUG
				printf("Packet read failed with error %d. Is the card locked and DMA enabled?\n", error);
			#endif
			if(allocated)
				free(buff);
			return NULL;
		}
		size -=error;
	}
	return buff;
}
예제 #14
0
int altix_toggle_dma(int fd)
{
	if(!is_initialized()) return ALTIX_NOT_INITIALIZED;
	if(ioctl(fd, ALTIX_IOCTL_DMA) == 0)
		return ALTIX_OK;
	return ALTIX_CARD_NOT_VALID;
}
예제 #15
0
 int altix_release_card(int fd, int id)
 {
	int cid = id;
	if(!is_initialized()) return ALTIX_NOT_INITIALIZED;
	if(ioctl(fd, ALTIX_IOCTL_RELEASE, &cid) == 0)
	{
		#ifdef ALTIX_DEBUG
			printf("libaltix: unocked %d \n", id);
		#endif
		return ALTIX_OK;
	}
	if(errno == EBUSY)
	{
		#ifdef ALTIX_DEBUG
			printf("libaltix:Card %d is not locked by this process\n", id);
		#endif
		return ALTIX_CARD_BUSY;
	}
	else
	{
		#ifdef ALTIX_DEBUG
			printf("libaltix: Could not find card with id %d\n", id);
		#endif
		return ALTIX_CARD_NOT_VALID;
	}
 }
예제 #16
0
Status SocketEventSubscriber::Callback(const ECRef& ec, const SCRef&) {
  if (ec->syscall == AUDIT_SYSCALL_CONNECT) {
    if (ec->fields.count("exit") && ec->fields.at("exit") != "-115") {
      // The connect syscall may want an exit with EINPROGRESS.
    }
  } else if (ec->type == AUDIT_TYPE_SYSCALL &&
             ec->syscall != AUDIT_SYSCALL_BIND) {
    return Status(0);
  }

  auto fields = asm_.add(ec->audit_id, ec->type, ec->fields);
  if (ec->syscall == AUDIT_SYSCALL_CONNECT) {
    asm_.set(ec->audit_id, "action", "connect");
  } else if (ec->syscall == AUDIT_SYSCALL_BIND) {
    asm_.set(ec->audit_id, "action", "bind");
  }

  if (fields.is_initialized()) {
    if ((*fields)["action"] == "bind") {
      (*fields)["local_port"] = std::move((*fields)["remote_port"]);
      (*fields)["local_address"] = std::move((*fields)["remote_address"]);
    }
    add(*fields);
  }

  return Status(0);
}
예제 #17
0
void Compiler::compile_method(ciEnv* env, ciMethod* method, int entry_bci) {

  if (!is_initialized()) {
    initialize();
  }
  // invoke compilation
#ifdef TIERED
  // We are thread in native here...
  CompilerThread* thread = CompilerThread::current();
  {
    ThreadInVMfromNative tv(thread);
    MutexLocker only_one (C1_lock, thread);
    while ( _compiling) {
      C1_lock->wait();
    }
    _compiling = true;
  }
#endif // TIERED
  {
    // We are nested here because we need for the destructor
    // of Compilation to occur before we release the any
    // competing compiler thread
    ResourceMark rm;
    Compilation c(this, env, method, entry_bci);
  }
#ifdef TIERED
  {
    ThreadInVMfromNative tv(thread);
    MutexLocker only_one (C1_lock, thread);
    _compiling = false;
    C1_lock->notify();
  }
#endif // TIERED
}
예제 #18
0
const std::string& osqueryHomeDirectory() {
  static std::string homedir;

  if (homedir.size() == 0) {
    // Try to get the caller's home directory
    boost::system::error_code ec;
    auto userdir = getHomeDirectory();
    if (userdir.is_initialized() && isWritable(*userdir).ok()) {
      auto osquery_dir = (fs::path(*userdir) / ".osquery");
      if (isWritable(osquery_dir) ||
          boost::filesystem::create_directories(osquery_dir, ec)) {
        homedir = osquery_dir.make_preferred().string();
        return homedir;
      }
    }

    // Fail over to a temporary directory (used for the shell).
    auto temp =
        fs::temp_directory_path(ec) / fs::unique_path("osquery%%%%%%%%", ec);
    boost::filesystem::create_directories(temp, ec);
    homedir = temp.make_preferred().string();
  }

  return homedir;
}
예제 #19
0
QueryData genScheduledTasks(QueryContext& context) {
  QueryData results;

  // First process all tasks in the root folder
  enumerateTasksForFolder("\\", results);

  // We attempt to derive the location of the tasks folder
  auto sysRoot = getEnvVar("SystemRoot");
  if (!sysRoot.is_initialized()) {
    return results;
  }
  auto sysTaskPath = *sysRoot + "\\System32\\Tasks";

  // Then process all tasks in subsequent folders
  std::vector<std::string> taskPaths;
  listDirectoriesInDirectory(sysTaskPath, taskPaths, true);
  for (const auto& path : taskPaths) {
    if (sysTaskPath.size() >= path.size()) {
      VLOG(1) << "Invalid task path " << path;
      continue;
    }
    auto taskPath =
        "\\" + join(split(path.substr(sysTaskPath.size(),
                                      (path.size() - sysTaskPath.size())),
                          "\\"),
                    "\\");
    enumerateTasksForFolder(taskPath, results);
  }

  return results;
}
예제 #20
0
파일: Music.cpp 프로젝트: xor-mind/solarus
/**
 * @brief Exits the music system.
 */
void Music::quit() {
  if (is_initialized()) {
    delete spc_decoder;
    delete it_decoder;
    all_musics.clear();
  }
}
예제 #21
0
QueryData genChocolateyPackages(QueryContext& context) {
  QueryData results;

  auto chocoEnvInstall = getEnvVar("ChocolateyInstall");

  fs::path chocoInstallPath;
  if (chocoEnvInstall.is_initialized()) {
    chocoInstallPath = fs::path(*chocoEnvInstall);
  }

  if (chocoInstallPath.empty()) {
    LOG(WARNING) << "Did not find chocolatey path environment variable";
    return results;
  }

  auto nuspecPattern = chocoInstallPath / "lib/%/%.nuspec";
  std::vector<std::string> manifests;
  resolveFilePattern(nuspecPattern, manifests, GLOB_FILES);

  for (const auto& pkg : manifests) {
    Row r;
    auto s = genPackage(pkg, r);
    if (!s.ok()) {
      VLOG(1) << "Failed to parse " << pkg << " with " << s.getMessage();
    }
    results.push_back(r);
  }

  return results;
}
예제 #22
0
파일: Music.cpp 프로젝트: Aerospyke/solarus
/**
 * @brief Creates a new music.
 * @param music_id id of the music (a file name)
 */
Music::Music(const MusicId& music_id):
  id(music_id) {

  if (!is_initialized() || music_id == none) {
    return;
  }

  // compute the file name
  file_name = (std::string) "musics/" + music_id;

  // get the format
  size_t index = music_id.find_last_of(".");
  Debug::check_assertion(index != std::string::npos && index != music_id.size(),
    StringConcat() << "Invalid music file name: " << music_id);
  std::string extension = music_id.substr(index + 1);

  if (extension == "spc" || extension == "SPC" || extension == "Spc") {
    format = SPC;
  }
  else if (extension == "it" || extension == "IT" || extension == "It") {
    format = IT;
  }
  else if (extension == "ogg" || extension == "OGG" || extension == "Ogg") {
    format = OGG;
  }
  else {
    Debug::die(StringConcat() << "Unrecognized music file format: " << music_id);
  }

  for (int i = 0; i < nb_buffers; i++) {
    buffers[i] = AL_NONE;
  }
  source = AL_NONE;
}
예제 #23
0
		_nes_rom::~_nes_rom(void)
		{

			if(is_initialized()) {
				uninitialize();
			}
		}
예제 #24
0
파일: instance.c 프로젝트: AndreG-P/appfs
/* checks if a vector is a feasible point of the LP */
int is_Solution(bip inst, int* test){
    assert(is_initialized(inst));
    for (int i=0; i<inst.rows; ++i){
        if (scalar_product(get_elem(inst, i, 0),test, inst.columns)>inst.vector[i]) return 0;
    }
    return 1;
}
예제 #25
0
    bool PureClientContext::m_connectCallbacksOnPath(std::string const &path) {
        /// Start by removing handler from interface tree and handler container
        /// for this path, if found. Ensures that if we early-out (fail to set
        /// up a handler) we don't have a leftover one still active.
        m_interfaces.eraseHandlerForPath(path);

        auto source = common::resolveTreeNode(m_pathTree, path);
        if (!source.is_initialized()) {
            OSVR_DEV_VERBOSE("Could not resolve source for " << path);
            return false;
        }
        auto handler = m_factory.invokeFactory(
            *source, m_interfaces.getInterfacesForPath(path), *this);
        if (handler) {
            OSVR_DEV_VERBOSE("Successfully produced handler for " << path);
            // Store the new handler in the interface tree
            auto oldHandler = m_interfaces.replaceHandlerForPath(path, handler);
            BOOST_ASSERT_MSG(
                !oldHandler,
                "We removed the old handler before so it should be null now");
            return true;
        }

        OSVR_DEV_VERBOSE("Could not produce handler for " << path);
        return false;
    }
bool IterQuantityAccessContiguous<T_info>::updated_k(int offset) const {
  if( !is_initialized() )
    return false;
  if( ( offset > max_offset_ ) || ( offset < max_offset_ - num_quantities_ + 1 ) )
    return false;
  return updated_[max_offset_ - offset];
}
inline
void ExampleNLPFirstOrder::assert_is_initialized() const
{
  typedef NLPInterfacePack::NLP NLP;
  if( !is_initialized() )
    throw NLP::UnInitialized("ExampleNLPFirstOrder::assert_is_initialized() : Error, "
      "ExampleNLPFirstOrder::initialize() has not been called yet." );
}
예제 #28
0
파일: Music.cpp 프로젝트: akimi634/solarus
/**
 * \brief Exits the music system.
 */
void Music::quit() {

  if (is_initialized()) {
    current_music = nullptr;
    spc_decoder = nullptr;
    it_decoder = nullptr;
  }
}
예제 #29
0
TEST_F(ProcessTests, test_envVar) {
  auto val = getEnvVar("GTEST_OSQUERY");
  EXPECT_FALSE(val);
  EXPECT_FALSE(val.is_initialized());

  EXPECT_TRUE(setEnvVar("GTEST_OSQUERY", "true"));

  val = getEnvVar("GTEST_OSQUERY");
  EXPECT_FALSE(!val);
  EXPECT_TRUE(val.is_initialized());
  EXPECT_EQ(*val, "true");

  EXPECT_TRUE(unsetEnvVar("GTEST_OSQUERY"));

  val = getEnvVar("GTEST_OSQUERY");
  EXPECT_FALSE(val);
  EXPECT_FALSE(val.is_initialized());
}
예제 #30
0
파일: instance.c 프로젝트: AndreG-P/appfs
int is_Solution_eq(bip inst, int* test){
    if (!is_initialized(inst)) {
        return 0;
    }
    for (int i=0; i<inst.rows; ++i){
        if (scalar_product(get_elem(inst, i, 0),test, inst.columns)!=inst.vector[i]) return 0;
    }
    return 1;
}