Пример #1
0
static void
received_announcement (GSSDPResourceBrowser *resource_browser,
                       SoupMessageHeaders   *headers)
{
        const char *header;

        header = soup_message_headers_get_one (headers, "NT");
        if (!header)
                return; /* No target specified */

        if (!check_target_compat (resource_browser, header))
                return; /* Target doesn't match */

        header = soup_message_headers_get_one (headers, "NTS");
        if (!header)
                return; /* No announcement type specified */

        /* Check announcement type */
        if      (strncmp (header,
                          SSDP_ALIVE_NTS,
                          strlen (SSDP_ALIVE_NTS)) == 0)
                resource_available (resource_browser, headers);
        else if (strncmp (header,
                          SSDP_BYEBYE_NTS,
                          strlen (SSDP_BYEBYE_NTS)) == 0)
                resource_unavailable (resource_browser, headers);
        else if (strncmp (header,
                          SSDP_UPDATE_NTS,
                          strlen (SSDP_UPDATE_NTS)) == 0)
                resource_update (resource_browser, headers);
}
Пример #2
0
static void
received_discovery_response (GSSDPResourceBrowser *resource_browser,
                             SoupMessageHeaders   *headers)
{
        const char *st;

        st = soup_message_headers_get_one (headers, "ST");
        if (!st)
                return; /* No target specified */

        if (!check_target_compat (resource_browser, st))
                return; /* Target doesn't match */

        resource_available (resource_browser, headers);
}
Пример #3
0
tiz_rm_error_t tizrmdb::release_all (const std::string &cname,
                                    const std::vector< unsigned char > &uuid)
{
  int rc = SQLITE_OK;
  char query[500];
  char uuid_str[129];
  int current = 0;
  int remaining = 0;

  tiz_uuid_str (&uuid[0], uuid_str);

  TIZ_LOG (TIZ_PRIORITY_TRACE,
           "tizrmdb::release_all : Releasing resources for "
           "component with uuid [%s]",
           uuid_str);

  for (int rid = 0; rid < TIZ_RM_RESOURCE_MAX; ++rid)
  {
    if (resource_acquired (uuid, rid, 0))
    {
      const std::string cname = vdata_[0];
      current = strtol (vdata_[vdata_.size () - 1].c_str (), NULL, 0);

      TIZ_LOG (TIZ_PRIORITY_TRACE,
               "'%s' uuid [%s] : Resource [%d] "
               "current allocation is "
               "[%d] units ...",
               cname.c_str (), uuid_str, rid, current);

      // Update allocation table to reflect the resource release...
      snprintf (query, sizeof(query),
                "delete from allocation where "
                "cname='%s' and uuid='%s' and resid=%d",
                cname.c_str (), uuid_str, rid);

      rc = run_query (query);

      if (SQLITE_OK != rc)
      {
        TIZ_LOG (TIZ_PRIORITY_TRACE,
                 "'%s' : Could not update allocation "
                 "table ",
                 cname.c_str ());
        return TIZ_RM_DATABASE_ACCESS_ERROR;
      }

      // Now, obtain the current resource availability
      resource_available (rid, 0);

      remaining = strtol (vdata_[vdata_.size () - 1].c_str (), NULL, 0);

      // Now update the resource table...
      snprintf (query, sizeof(query),
                "update resources set current=%d where resid=%d",
                remaining + current, rid);

      rc = run_query (query);

      if (SQLITE_OK != rc)
      {
        TIZ_LOG (TIZ_PRIORITY_TRACE,
                 "Could not update resource table "
                 "for resource [%s]",
                 rid);
        return TIZ_RM_DATABASE_ACCESS_ERROR;
      }

      TIZ_LOG (TIZ_PRIORITY_TRACE,
               "'%s':  Released [%d] units of "
               "resource  id [%d]",
               cname.c_str (), current, rid);
    }
  }

  return TIZ_RM_SUCCESS;
}
Пример #4
0
tiz_rm_error_t tizrmdb::release_resource (
    const unsigned int &rid, const unsigned int &quantity,
    const std::string &cname, const std::vector< unsigned char > &uuid,
    const unsigned int &grpid, const unsigned int &pri)
{
  int rc = SQLITE_OK;
  char query[500];
  char uuid_str[129];
  int current = 0;
  int requirement = 0;

  TIZ_LOG (TIZ_PRIORITY_TRACE,
           "tizrmdb::release_resource : "
           "'%s':  [%d] units of resource [%d]",
           cname.c_str (), quantity, rid);

  // Check that the component is provisioned and is allowed to access the
  // resource
  if (!comp_provisioned_with_resid (cname, rid))
  {
    TIZ_LOG (TIZ_PRIORITY_TRACE, "'%s' is not provisioned...", cname.c_str ());
    return TIZ_RM_COMPONENT_NOT_PROVISIONED;
  }

  requirement = strtol (vdata_[vdata_.size () - 1].c_str (), NULL, 0);
  // TODO: Replace this with proper error check
  assert (requirement >= 0);

  TIZ_LOG (TIZ_PRIORITY_TRACE,
           "'%s': provisioned requirement [%d] units, "
           "actually requested [%d] ...",
           cname.c_str (), requirement, quantity);

  if (quantity > (unsigned int) requirement)
  {
    TIZ_LOG (TIZ_PRIORITY_TRACE,
             "'%s': releasing [%d] units, "
             "but provisioned only [%d]",
             cname.c_str (), quantity, requirement);
    return TIZ_RM_NOT_ENOUGH_RESOURCE_PROVISIONED;
  }

  // Check that the resource was effectively acquired by the component
  if (!resource_acquired (uuid, rid, quantity))
  {
    TIZ_LOG (TIZ_PRIORITY_TRACE,
             "Resource [%d] cannot be released: "
             "not enough resource previously acquired",
             rid);
    return TIZ_RM_NOT_ENOUGH_RESOURCE_ACQUIRED;
  }

  current = strtol (vdata_[vdata_.size () - 1].c_str (), NULL, 0);

  TIZ_LOG (TIZ_PRIORITY_TRACE,
           "Resource [%d]: current allocation [%d] units ...", rid, current);

  tiz_uuid_str (&uuid[0], uuid_str);

  // Update allocation table to reflect the resource release...

  // ... first delete the the row...
  snprintf (query, sizeof(query),
            "delete from allocation where "
            "cname='%s' and uuid='%s' and resid=%d",
            cname.c_str (), uuid_str, rid);

  rc = run_query (query);

  if (SQLITE_OK != rc)
  {
    TIZ_LOG (TIZ_PRIORITY_TRACE,
             "'%s' : Could not update allocation "
             "table ",
             cname.c_str ());
    return TIZ_RM_DATABASE_ACCESS_ERROR;
  }

  //... now create a new one, only if there's some resource allocation
  // remaining
  if (current - quantity)
  {
    // TODO : This string is duplicated. Move to a constant
    snprintf (query, sizeof(query),
              "insert or replace into allocation (cname, uuid, grpid, pri, "
              "resid, allocation) values('%s', '%s', %d, %d, %d, %d)",
              cname.c_str (), uuid_str, grpid, pri, rid, current - quantity);

    rc = run_query (query);

    if (SQLITE_OK != rc)
    {
      TIZ_LOG (TIZ_PRIORITY_TRACE, "'%s' : Could not update allocation table",
               cname.c_str ());
      return TIZ_RM_DATABASE_ACCESS_ERROR;
    }
  }

  // Now, obtain the current resource availability
  if (!resource_available (rid, 0))
  {
    TIZ_LOG (TIZ_PRIORITY_TRACE, "Resource [%d] not available...", rid);
    return TIZ_RM_NOT_ENOUGH_RESOURCE_AVAILABLE;
  }

  current = strtol (vdata_[vdata_.size () - 1].c_str (), NULL, 0);

  // Now update the resource table...
  snprintf (query, sizeof(query),
            "update resources set current=%d where resid=%d",
            current + quantity, rid);

  rc = run_query (query);

  if (SQLITE_OK != rc)
  {
    TIZ_LOG (TIZ_PRIORITY_TRACE,
             "Could not update resource table "
             "for resource [%s]",
             rid);
    return TIZ_RM_DATABASE_ACCESS_ERROR;
  }

  TIZ_LOG (TIZ_PRIORITY_TRACE,
           "'%s' : Succesfully released [%d] units of "
           "resource id [%d]",
           cname.c_str (), quantity, rid);

  return TIZ_RM_SUCCESS;
}
Пример #5
0
tiz_rm_error_t tizrmdb::acquire_resource (
    const unsigned int &rid, const unsigned int &quantity,
    const std::string &cname, const std::vector< unsigned char > &uuid,
    const unsigned int &grpid, const unsigned int &pri)
{
  int rc = SQLITE_OK;
  char query[500];
  char uuid_str[129];
  int current = 0;
  int requirement = 0;

  tiz_uuid_str (&uuid[0], uuid_str);

  TIZ_LOG (TIZ_PRIORITY_TRACE,
           "tizrmdb::acquire_resource : "
           "'%s': Acquiring [%d] units of resource [%d] "
           "uuid [%s]",
           cname.c_str (), quantity, rid, uuid_str);

  // Check that the component is provisioned and is allowed access to the
  // resource
  if (!comp_provisioned_with_resid (cname, rid))
  {
    TIZ_LOG (TIZ_PRIORITY_TRACE,
             "tizrmdb::acquire_resource : "
             "'%s' is not provisioned...",
             cname.c_str ());
    return TIZ_RM_COMPONENT_NOT_PROVISIONED;
  }

  requirement = strtol (vdata_[vdata_.size () - 1].c_str (), NULL, 0);
  // TODO: Replace this with proper error check
  assert (requirement >= 0);

  TIZ_LOG (TIZ_PRIORITY_TRACE,
           "tizrmdb::acquire_resource : "
           "[%s]: provisioned requirement [%d] units, "
           "actually requested [%d] ...",
           cname.c_str (), requirement, quantity);

  if (quantity > (unsigned int) requirement)
  {
    TIZ_LOG (TIZ_PRIORITY_TRACE,
             "tizrmdb::acquire_resource : "
             "[%s]: requested [%d] units, but provisioned "
             "only [%d]",
             cname.c_str (), quantity, requirement);
    return TIZ_RM_NOT_ENOUGH_RESOURCE_PROVISIONED;
  }

  // Check that the requested resource is provisioned and there is availability
  if (!resource_available (rid, quantity))
  {
    TIZ_LOG (TIZ_PRIORITY_TRACE,
             "tizrmdb::acquire_resource : "
             "Resource [%d] not available...",
             rid);
    return TIZ_RM_NOT_ENOUGH_RESOURCE_AVAILABLE;
  }

  current = strtol (vdata_[vdata_.size () - 1].c_str (), NULL, 0);

  TIZ_LOG (TIZ_PRIORITY_TRACE,
           "tizrmdb::acquire_resource: "
           "Resource [%d]: available [%d] units ...",
           rid, current);

  snprintf (query, sizeof(query),
            "insert or replace into allocation (cname, uuid, grpid, "
            "pri, resid, allocation) "
            "values('%s', '%s', %d, %d, %d, %d)",
            cname.c_str (), uuid_str, grpid, pri, rid, quantity);

  rc = run_query (query);

  if (SQLITE_OK != rc)
  {
    TIZ_LOG (TIZ_PRIORITY_TRACE,
             "tizrmdb::acquire_resource : "
             "'%s' : Could not update allocation table",
             cname.c_str ());
    return TIZ_RM_DATABASE_ERROR;
  }

  snprintf (query, sizeof(query),
            "update resources set current=%d where resid=%d",
            current - quantity, rid);

  rc = run_query (query);

  if (SQLITE_OK != rc)
  {
    TIZ_LOG (TIZ_PRIORITY_TRACE,
             "tizrmdb::acquire_resource : "
             "Could not update resource table "
             "for resource [%s]",
             rid);
    return TIZ_RM_DATABASE_ERROR;
  }

  TIZ_LOG (TIZ_PRIORITY_TRACE,
           "tizrmdb::acquire_resource: "
           "Succesfully acquired resource [%d] for [%s]",
           rid, cname.c_str ());

  return TIZ_RM_SUCCESS;
}