Ejemplo n.º 1
0
    std::vector<std::shared_ptr<device_info>> context::query_devices() const
    {

        platform::backend_device_group devices(_backend->query_uvc_devices(), _backend->query_usb_devices(), _backend->query_hid_devices());

        return create_devices(devices, _playback_devices);
    }
Ejemplo n.º 2
0
		// Costructor with specific cl_platform_id
		platform(cl_platform_id m_platform_id)
		{

			// Initialise the clog object
			m_log = clog::getInstance();

			this->m_platform_id = m_platform_id;

			//std::cout << "The platform name is " << name().c_str() << std::endl;
			//std::cout << "The platform version is " << version().c_str() << std::endl;
			m_log->write("The platform name is ");
			m_log->write(name().c_str());
			m_log->write("\n");

			m_log->write("	The platform version is ");
			m_log->write(version().c_str());
			m_log->write("\n");

			m_devices_count = get_device_count();

			create_devices();
		}
Ejemplo n.º 3
0
    void context::on_device_changed(platform::backend_device_group old,
                                    platform::backend_device_group curr,
                                    const std::map<std::string, std::shared_ptr<device_info>>& old_playback_devices,
                                    const std::map<std::string, std::shared_ptr<device_info>>& new_playback_devices)
    {
        auto old_list = create_devices(old, old_playback_devices);
        auto new_list = create_devices(curr, new_playback_devices);

        if (librealsense::list_changed<std::shared_ptr<device_info>>(old_list, new_list, [](std::shared_ptr<device_info> first, std::shared_ptr<device_info> second) {return *first == *second; }))
        {

            std::vector<rs2_device_info> rs2_devices_info_added;
            std::vector<rs2_device_info> rs2_devices_info_removed;

            auto devices_info_removed = subtract_sets(old_list, new_list);

            for (size_t i = 0; i < devices_info_removed.size(); i++)
            {
                rs2_devices_info_removed.push_back({ shared_from_this(), devices_info_removed[i] });
                LOG_DEBUG("\nDevice disconnected:\n\n" << std::string(devices_info_removed[i]->get_device_data()));
            }

            auto devices_info_added = subtract_sets(new_list, old_list);
            for (size_t i = 0; i < devices_info_added.size(); i++)
            {
                rs2_devices_info_added.push_back({ shared_from_this(), devices_info_added[i] });
                LOG_DEBUG("\nDevice connected:\n\n" << std::string(devices_info_added[i]->get_device_data()));
            }

            std::map<uint64_t, devices_changed_callback_ptr> devices_changed_callbacks;
            {
                std::lock_guard<std::mutex> lock(_devices_changed_callbacks_mtx);
                devices_changed_callbacks = _devices_changed_callbacks;
            }

            for (auto& kvp : devices_changed_callbacks)
            {
                try
                {
                    kvp.second->on_devices_changed(new rs2_device_list({ shared_from_this(), rs2_devices_info_removed }),
                                                   new rs2_device_list({ shared_from_this(), rs2_devices_info_added }));
                }
                catch (...)
                {
                    LOG_ERROR("Exception thrown from user callback handler");
                }
            }

            if (_devices_changed_callback)
            {
                try
                {
                    _devices_changed_callback->on_devices_changed(new rs2_device_list({ shared_from_this(), rs2_devices_info_removed }),
                        new rs2_device_list({ shared_from_this(), rs2_devices_info_added }));
                }
                catch (...)
                {
                    LOG_ERROR("Exception thrown from user callback handler");
                }    
            }
        }
    }