void SoundCloudCAPI_performMethodWithCallback(SoundCloudCAPI *api,const char* httpMethod,const char *resource,SoundCloudCAPI_Parameter* parameters,int num_params,SoundCloudCAPICallback callback,void *userData)
{
	SoundCloudCAPIThread *thread_data=(SoundCloudCAPIThread*)malloc(sizeof(SoundCloudCAPIThread));
	thread_data->api=api;
	thread_data->callback=callback;
	thread_data->callback_data=userData;
	thread_data->httpMethod=sc_strdup(httpMethod);

	thread_data->error=ConstructStringsForMethod(api,httpMethod,resource,parameters,num_params,&thread_data->url,&thread_data->body,&thread_data->bodylen,&thread_data->header);


#ifndef WIN
	pthread_t thread;
	pthread_create(&thread,0,SoundCloudCAPI_thread,thread_data);
#else
	CreateThread (0,0,SoundCloudCAPI_thread,thread_data,0,0);
#endif
}
예제 #2
0
void FKG_SetVerbose(BYTE level, const char *filename)
{
  if (trace_file != NULL)
  {
    free(trace_file);
    trace_file = NULL;
  }

  if (filename != NULL)
	{
		FKG_Trace(trace_level, "Trace file set to %s", filename);
		trace_file = sc_strdup(filename);
		FKG_Trace(trace_level, "Trace file set to %s", trace_file);
	}

	trace_level = level;    
	FKG_Trace(trace_level, "Trace level set to %02X", level);
}
/**f* Fkg485.dll/FKG485_Create
 *
 * NAME
 *   FKG485_Create
 *
 * DESCRIPTION
 *  Instanciate a new context to communicate with a device (either a
 *  FunkyGate or a HandyDrummer)
 *
 * SYNOPSIS
 *   BOOL FKG485_Create(const char *comm_name, BYTE device_addr, const char *device_name);
 *
 * INPUTS
 *   const char *comm_name : the communication port
 *   BYTE        device_addr   : the device's address
 *   const char *device_name   : the device's "friendly-name"
 *
 * RETURNS
 *   TRUE  : success, context created
 *   FALSE : can't create the context (out of memory or device_name invalid)
 *
 * SEE ALSO
 *   FKG485_Start
 *   FKG485_Destroy
 *
 **/
FKG485_LIB BOOL FKG485_API FKG485_Create(const char *comm_name, BYTE device_addr, const char *device_name)
{
  FKG_DEVICE_CTX_ST *device_ctx  = NULL;
  FKG485_DEVICE_ST  *_device = NULL;

  if (device_name != NULL)
  {
    /* Check the name isn't already in use */
    device_ctx = FKG_FindDevice(device_name);
    if (device_ctx != NULL)
      return FALSE;
  }

  device_ctx = (FKG_DEVICE_CTX_ST *) calloc(1, sizeof(FKG_DEVICE_CTX_ST));
  if (device_ctx == NULL)
    goto failed;

  if (device_name != NULL)
  {
    device_ctx->Name = sc_strdup(device_name);
  } else
  {
    char buffer[64];
    DWORD i = 1 + FKG_GetDeviceCount();

    do
    {
      sprintf(buffer, "Device %d", i);
    } while (FKG_FindDevice(buffer) != NULL);

    device_ctx->Name = sc_strdup(buffer);
  }

  if (device_ctx->Name == NULL)
    goto failed;

  _device = FKG485_AttachDevice(comm_name, device_addr);
  if (_device == NULL)
		goto failed;

	 _device->_device_ctx = device_ctx;
  device_ctx->CtxData = _device;

  if (!FKG_InsertDevice(device_ctx))
    goto failed;

  if (FKG_Callbacks.OnStatusChange != NULL)
    if (!FKG_Callbacks.OnStatusChange(device_ctx->Name, FKG_STATUS_CREATED))
      goto failed;

  return TRUE;

failed:
  if (_device != NULL)
  {
    FKG485_DetachDevice(_device);
    free(_device);
  }
  if (device_ctx != NULL)
  {
    if (device_ctx->Name != NULL)
      free(device_ctx->Name);
    free(device_ctx);
  }

  return FALSE;
}