コード例 #1
0
ファイル: cache.c プロジェクト: Illuminux/forked-daapd
void
cache_daap_add(const char *query, const char *ua, int msec)
{
  struct cache_command *cmd;

  if (!g_initialized)
    return;

  cmd = (struct cache_command *)malloc(sizeof(struct cache_command));
  if (!cmd)
    {
      DPRINTF(E_LOG, L_CACHE, "Could not allocate cache_command\n");
      return;
    }

  memset(cmd, 0, sizeof(struct cache_command));

  cmd->nonblock = 1;

  cmd->func = cache_daap_query_add;
  cmd->arg.query = strdup(query);
  cmd->arg.ua = strdup(ua);
  cmd->arg.msec = msec;

  nonblock_command(cmd);
}
コード例 #2
0
ファイル: lastfm.c プロジェクト: feihugao/forked-daapd
/* Thread: http and player */
int
lastfm_scrobble(int id)
{
  struct lastfm_command *cmd;
  int ret;

  DPRINTF(E_DBG, L_LASTFM, "Got LastFM scrobble request\n");

  // LastFM is disabled because we already tried looking for a session key, but failed
  if (g_disabled)
    return -1;

  // No session key in mem or in db
  if (!g_session_key)
    g_session_key = db_admin_get("lastfm_sk");

  if (!g_session_key)
    {
      DPRINTF(E_INFO, L_LASTFM, "No valid LastFM session key\n");
      g_disabled = 1;
      return -1;
    }

  // Spawn LastFM thread
  ret = lastfm_init();
  if (ret < 0)
    {
      g_disabled = 1;
      return -1;
    }
  g_initialized = 1;

  // Send scrobble command to the thread
  cmd = (struct lastfm_command *)malloc(sizeof(struct lastfm_command));
  if (!cmd)
    {
      DPRINTF(E_LOG, L_LASTFM, "Could not allocate lastfm_command\n");
      return -1;
    }

  memset(cmd, 0, sizeof(struct lastfm_command));

  cmd->nonblock = 1;
  cmd->func = scrobble;
  cmd->arg.id = id;

  nonblock_command(cmd);

  return 0;
}
コード例 #3
0
ファイル: cache.c プロジェクト: Illuminux/forked-daapd
void
cache_daap_trigger(void)
{
  struct cache_command *cmd;

  if (!g_initialized)
    return;

  cmd = (struct cache_command *)malloc(sizeof(struct cache_command));
  if (!cmd)
    {
      DPRINTF(E_LOG, L_CACHE, "Could not allocate cache_command\n");
      return;
    }

  memset(cmd, 0, sizeof(struct cache_command));

  cmd->nonblock = 1;

  cmd->func = cache_daap_update_timer;

  nonblock_command(cmd);
}
コード例 #4
0
ファイル: worker.c プロジェクト: topherx/forked-daapd
/* Thread: player */
void
worker_execute(void (*cb)(void *), void *cb_arg, size_t arg_size, int delay)
{
  struct worker_command *cmd;
  void *argcpy;

  DPRINTF(E_DBG, L_MAIN, "Got worker execute request\n");

  cmd = (struct worker_command *)malloc(sizeof(struct worker_command));
  if (!cmd)
    {
      DPRINTF(E_LOG, L_MAIN, "Could not allocate worker_command\n");
      return;
    }

  memset(cmd, 0, sizeof(struct worker_command));

  argcpy = malloc(arg_size);
  if (!argcpy)
    {
      DPRINTF(E_LOG, L_MAIN, "Out of memory\n");
      return;
    }

  memcpy(argcpy, cb_arg, arg_size);

  cmd->nonblock = 1;
  cmd->func = execute;
  cmd->arg.cb = cb;
  cmd->arg.cb_arg = argcpy;
  cmd->arg.delay = delay;

  nonblock_command(cmd);

  return;
}
コード例 #5
0
ファイル: lastfm.c プロジェクト: feihugao/forked-daapd
/* Thread: filescanner */
void
lastfm_login(char *path)
{
  struct lastfm_command *cmd;
  struct keyval *kv;
  char *username;
  char *password;
  int ret;

  DPRINTF(E_DBG, L_LASTFM, "Got LastFM login request\n");

  // Delete any existing session key
  if (g_session_key)
    free(g_session_key);

  g_session_key = NULL;

  db_admin_delete("lastfm_sk");

  // Read the credentials file
  ret = credentials_read(path, &username, &password);
  if (ret < 0)
    return;

  // Enable LastFM now that we got a login attempt
  g_disabled = 0;

  kv = keyval_alloc();
  if (!kv)
    {
      free(username);
      free(password);
      return;
    }

  ret = ( (keyval_add(kv, "api_key", g_api_key) == 0) &&
          (keyval_add(kv, "username", username) == 0) &&
          (keyval_add(kv, "password", password) == 0) );

  free(username);
  free(password);

  if (!ret)
    {
      keyval_clear(kv);
      return;
    }

  // Spawn thread
  ret = lastfm_init();
  if (ret < 0)
    {
      g_disabled = 1;
      return;
    }
  g_initialized = 1;

  // Send login command to the thread
  cmd = (struct lastfm_command *)malloc(sizeof(struct lastfm_command));
  if (!cmd)
    {
      DPRINTF(E_LOG, L_LASTFM, "Could not allocate lastfm_command\n");
      return;
    }

  memset(cmd, 0, sizeof(struct lastfm_command));

  cmd->nonblock = 1;
  cmd->func = login;
  cmd->arg.kv = kv;

  nonblock_command(cmd);

  return;
}