Exemplo n.º 1
0
/*
 * rasqal_world_register_query_result_format_factory:
 * @world: rasqal world
 * @register_factory: pointer to function to call to register the factory
 * 
 * INTERNAL - Register a query result format via a factory.
 *
 * All strings set in the @factory method are shared with the
 * #rasqal_query_result_format_factory
 *
 * Return value: new factory object or NULL on failure
 **/
rasqal_query_results_format_factory*
rasqal_world_register_query_results_format_factory(rasqal_world* world,
                                                   int (*register_factory)(rasqal_query_results_format_factory*))
{
  rasqal_query_results_format_factory *factory = NULL;
  
  factory = RASQAL_CALLOC(rasqal_query_results_format_factory*, 1, 
                          sizeof(*factory));
  if(!factory)
    return NULL;

  factory->world = world;

  if(raptor_sequence_push(world->query_results_formats, factory))
    return NULL; /* on error, factory is already freed by the sequence */
  
  /* Call the factory registration function on the new object */
  if(register_factory(factory))
    /* factory is owned and freed by the query_results_formats sequence */
    return NULL;
  
  factory->desc.flags = 0;
  if(factory->get_rowsource)
    factory->desc.flags |= RASQAL_QUERY_RESULTS_FORMAT_FLAG_READER;
  if(factory->write)
    factory->desc.flags |= RASQAL_QUERY_RESULTS_FORMAT_FLAG_WRITER;

  if(raptor_syntax_description_validate(&factory->desc)) {
    rasqal_log_error_simple(world, RAPTOR_LOG_LEVEL_ERROR, NULL,
                            "Result query result format description failed to validate\n");
    goto tidy;
  }

#if defined(RASQAL_DEBUG) && RASQAL_DEBUG > 1
  RASQAL_DEBUG3("Registered query result format %s with context size %d\n",
                factory->desc.names[0], factory->context_length);
#endif

  return factory;

  /* Clean up on failure */
  tidy:
  rasqal_free_query_results_format_factory(factory);
  return NULL;
}
Exemplo n.º 2
0
/*
 * rasqal_query_language_register_factory:
 * @factory: pointer to function to call to register the factory
 * 
 * INTERNAL - Register a query language syntax handled by a query factory
 *
 * Return value: new factory or NULL on failure
 **/
RASQAL_EXTERN_C
rasqal_query_language_factory*
rasqal_query_language_register_factory(rasqal_world *world,
                                       int (*factory) (rasqal_query_language_factory*))
{
  rasqal_query_language_factory *query = NULL;
  
  query = (rasqal_query_language_factory*)RASQAL_CALLOC(rasqal_query_language_factory, 1,
                                                        sizeof(*query));
  if(!query)
    goto tidy;

  query->world = world;
  
  if(raptor_sequence_push(world->query_languages, query))
    return NULL; /* on error, query is already freed by the sequence */
  
  /* Call the query registration function on the new object */
  if(factory(query))
    return NULL; /* query is owned and freed by the query_languages sequence */
  
  if(raptor_syntax_description_validate(&query->desc)) {
    rasqal_log_error_simple(world, RAPTOR_LOG_LEVEL_ERROR, NULL,
                            "Query language format description failed to validate\n");
    goto tidy;
  }

#if defined(RASQAL_DEBUG) && RASQAL_DEBUG > 1
  RASQAL_DEBUG3("Registered query language %s with context size %d\n",
                query->names[0], query->context_length);
#endif

  return query;

  /* Clean up on failure */
  tidy:
  if(query)
    rasqal_free_query_language_factory(query);

  return NULL;
}
Exemplo n.º 3
0
/*
 * raptor_serializer_register_factory:
 * @world: raptor_world object
 * @name: the short syntax name
 * @label: readable label for syntax
 * @mime_type: MIME type of the syntax generated by the serializer (or NULL)
 * @uri_string: URI string of the syntax (or NULL)
 * @factory: pointer to function to call to register the factory
 * 
 * INTERNAL - Register a syntax that can be generated by a serializer factory
 *
 * Return value: non-0 on failure
 **/
RAPTOR_EXTERN_C
raptor_serializer_factory*
raptor_serializer_register_factory(raptor_world* world,
                                   int (*factory) (raptor_serializer_factory*)) 
{
  raptor_serializer_factory *serializer;
  
  serializer = RAPTOR_CALLOC(raptor_serializer_factory*, 1, sizeof(*serializer));
  if(!serializer)
    return NULL;

  serializer->world = world;

  serializer->desc.mime_types = NULL;
  
  if(raptor_sequence_push(world->serializers, serializer))
    return NULL; /* on error, serializer is already freed by the sequence */

  /* Call the serializer registration function on the new object */
  if(factory(serializer))
    return NULL; /* serializer is owned and freed by the serializers sequence */
  
  if(raptor_syntax_description_validate(&serializer->desc)) {
    raptor_log_error(world, RAPTOR_LOG_LEVEL_ERROR, NULL,
                     "Serializer description failed to validate\n");
    goto tidy;
  }

#if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1
  RAPTOR_DEBUG2("Registered serializer %s\n", serializer->desc.names[0]);
#endif

  return serializer;

  /* Clean up on failure */
  tidy:
  raptor_free_serializer_factory(serializer);
  return NULL;
}