Exemple #1
0
inline future<HostIterator> copy_to_host_async(DeviceIterator first,
                                               DeviceIterator last,
                                               HostIterator result,
                                               command_queue &queue)
{
    typedef typename
        std::iterator_traits<DeviceIterator>::value_type
        value_type;

    size_t count = iterator_range_size(first, last);
    if(count == 0){
        return future<HostIterator>();
    }

    const buffer &buffer = first.get_buffer();
    size_t offset = first.get_index();

    event event_ =
        queue.enqueue_read_buffer_async(buffer,
                                        offset * sizeof(value_type),
                                        count * sizeof(value_type),
                                        ::boost::addressof(*result));

    return make_future(iterator_plus_distance(result, count), event_);
}
// If serial is 0, any Phantom device will suffice
Phantom* Phantom::findPhantom(unsigned int serial)
{
  // TODO Cache the Phantom devices and recreate list upon bus resets (much more efficient, assuming that it does not take too much resources to create the list...)

  FirewireDevice *dev;
  DeviceIterator *i = DeviceIterator::createInstance();

  for (dev = i->next(); dev; dev = i->next())
  {
    if (dev->isSensableDevice())
    {
      uint32_t device_serial = readDeviceSerial(dev);
      if (serial != 0 && serial != device_serial)
      {
        delete dev;
        continue;
      }

      //We have found a Phantom device
      delete i;
      return new Phantom(dev);
    }

    delete dev;
  }
  delete i;

  // We failed to find a(n unused) Phantom device...
  return 0;
}
Exemple #3
0
inline DeviceIterator copy_to_device(HostIterator first,
                                     HostIterator last,
                                     DeviceIterator result,
                                     command_queue &queue,
                                     const wait_list &events)
{
    typedef typename
        std::iterator_traits<DeviceIterator>::value_type
        value_type;
    typedef typename
        std::iterator_traits<DeviceIterator>::difference_type
        difference_type;

    size_t count = iterator_range_size(first, last);
    if(count == 0){
        return result;
    }

    size_t offset = result.get_index();

    queue.enqueue_write_buffer(result.get_buffer(),
                               offset * sizeof(value_type),
                               count * sizeof(value_type),
                               ::boost::addressof(*first),
                               events);

    return result + static_cast<difference_type>(count);
}
Exemple #4
0
inline DeviceIterator copy_to_device_map(HostIterator first,
                                         HostIterator last,
                                         DeviceIterator result,
                                         command_queue &queue,
                                         const wait_list &events)
{
    typedef typename
        std::iterator_traits<DeviceIterator>::value_type
        value_type;
    typedef typename
        std::iterator_traits<DeviceIterator>::difference_type
        difference_type;

    size_t count = iterator_range_size(first, last);
    if(count == 0){
        return result;
    }

    size_t offset = result.get_index();

    // map result buffer to host
    value_type *pointer = static_cast<value_type*>(
        queue.enqueue_map_buffer(
            result.get_buffer(),
            CL_MAP_WRITE,
            offset * sizeof(value_type),
            count * sizeof(value_type),
            events
        )
    );

    // copy [first; last) to result buffer
    std::copy(first, last, pointer);

    // unmap result buffer
    boost::compute::event unmap_event = queue.enqueue_unmap_buffer(
        result.get_buffer(),
        static_cast<void*>(pointer)
    );
    unmap_event.wait();

    return result + static_cast<difference_type>(count);
}
Exemple #5
0
Service ControlPoint::getWanIpConnectionService(Device& igd)
{
   /* Note:
    *
    * An InternetGatewayDevice has a WANDevice in it. Inside the WANDevice
    * there is a WANConnectionDevice. The WANConnectionDevice may have a
    * WANIPConnectionServices which provides port mapping services.
    */

   // get the wan device
   Device wd(NULL);
   {
      igd["devices"]->setType(Array);
      DeviceIterator di = igd["devices"].getIterator();
      while(wd.isNull() && di->hasNext())
      {
         Device& next = di->next();
         if(strcmp(next["deviceType"]->getString(), UPNP_DEVICE_TYPE_WAN) == 0)
         {
            // found wan device
            wd = next;

            MO_CAT_DEBUG(MO_UPNP_CAT,
               "Found device '" UPNP_DEVICE_TYPE_WAN "'");
         }
      }
   }

   // get the wan connection device
   Device wcd(NULL);
   if(!wd.isNull())
   {
      wd["devices"]->setType(Array);
      DeviceIterator di = wd["devices"].getIterator();
      while(wcd.isNull() && di->hasNext())
      {
         Device& next = di->next();
         if(strcmp(
            next["deviceType"]->getString(),
            UPNP_DEVICE_TYPE_WAN_CONNECTION) == 0)
         {
            // found wan connection device
            wcd = next;

            MO_CAT_DEBUG(MO_UPNP_CAT,
               "Found device '" UPNP_DEVICE_TYPE_WAN_CONNECTION "'");
         }
      }
   }

   // get the wan ip connection service
   Service wipcs(NULL);
   if(!wcd.isNull())
   {
      wcd["services"]->setType(Array);
      ServiceIterator si = wcd["services"].getIterator();
      while(wipcs.isNull() && si->hasNext())
      {
         Service& next = si->next();
         if(strcmp(
            next["serviceType"]->getString(),
            UPNP_SERVICE_TYPE_WAN_IP_CONNECTION) == 0)
         {
            // found wan ip connection service
            wipcs = next;

            MO_CAT_DEBUG(MO_UPNP_CAT,
               "Found service '" UPNP_SERVICE_TYPE_WAN_IP_CONNECTION "'");
         }
      }
   }

   return wipcs;
}