C quickstart

The native package installs the public C header, shared library, CMake package, a buildable example, and a small deterministic media fixture. Rust and Cargo are not required on the consuming machine.

Assuming PostProject is installed under /opt/postproject, build and run the installed example with:

cmake \
  -S /opt/postproject/share/doc/postproject/examples/c \
  -B build/postproject-c-example \
  -DCMAKE_PREFIX_PATH=/opt/postproject \
  -DCMAKE_BUILD_TYPE=Release
cmake --build build/postproject-c-example --config Release
ctest --test-dir build/postproject-c-example \
  --build-config Release --output-on-failure

The test creates c-example.pproj, imports the installed sample-media.dat, commits the transaction, and prints the asset ID, its representation count, and the location of its original. Its production path must not already exist.

For an application target, consume the same package normally:

find_package(PostProject 0.9 REQUIRED CONFIG)
target_link_libraries(my_application PRIVATE PostProject::postproject)

The example program

The installed example is the program below. It follows the ownership rules that apply to every C integration:

  • Every handle is caller-owned. Productions, transactions, result sets, and error handles are each released exactly once with their release function. Release functions accept NULL, so starting every handle as NULL gives one cleanup path for success and failure alike.

  • Errors are optional, owned handles. A failed call returns its status code and, when out_error is not NULL, transfers an error handle. Stop at the first failure so an error that still has to be released is never overwritten. Branch on the status code; the message is diagnostic text and is borrowed from the error handle.

  • Only commit makes staged work durable. Releasing a transaction that was not committed discards everything staged in it.

  • Result-set strings are borrowed. A string read from a result set, such as a locator URI, stays valid only until the set is released.

#include <postproject/postproject.h>

#include <stdio.h>

static void print_asset_id(const pp_asset_id_t *id) {
  for (size_t index = 0; index < sizeof(id->bytes); ++index) {
    printf("%02x", id->bytes[index]);
  }
  putchar('\n');
}

int main(int argc, char **argv) {
  if (argc != 3) {
    fprintf(stderr,
            "usage: postproject-c-example OUTPUT_PRODUCTION MEDIA_FILE\n");
    return 2;
  }

  /* Every handle starts as NULL and is released exactly once at the end.
   * Release functions accept NULL, so one cleanup path serves every outcome. */
  pp_production_t *production = NULL;
  pp_transaction_t *transaction = NULL;
  pp_representation_set_t *representations = NULL;
  pp_error_t *error = NULL;
  pp_asset_id_t asset_id = {{0}};
  pp_representation_id_t representation_id = {{0}};

  /* Each fallible call returns a status code. On failure it transfers a
   * caller-owned error handle, so the chain stops at the first failure and
   * never overwrites an error that still has to be released. */
  pp_error_code_t status =
      pp_production_create(argv[1], "C quickstart", &production, &error);
  if (status == PP_OK) {
    status = pp_production_begin_edit(production, NULL, NULL, &transaction, &error);
  }
  /* A media source describes the file to import; the transaction borrows it
   * only for the call. */
  if (status == PP_OK) {
    status = pp_transaction_import_file(transaction, argv[2], NULL, &asset_id, &representation_id, &error);
  }
  /* Staged work becomes durable only on commit. Releasing a transaction that
   * was not committed discards everything staged in it. */
  if (status == PP_OK) {
    pp_commit_receipt_t commit_receipt;
    status = pp_transaction_commit(transaction, &commit_receipt, &error);
  }
  /* The result set is caller-owned; strings read from it borrow the set. */
  if (status == PP_OK) {
    status = pp_production_representation(production, representation_id,
                                           &representations, &error);
  }
  pp_locator_id_t locator_id = {{0}};
  const char *uri = NULL;
  pp_locator_availability_t availability = 0;
  uint8_t has_last_seen = 0;
  int64_t last_seen = 0;
  uint8_t has_sequence_naming = 0;
  pp_sequence_naming_t sequence_naming;
  if (status == PP_OK) {
    status = pp_representation_set_get_locator(
        representations, 0, 0, 0, &locator_id, &uri, &availability,
        &has_last_seen, &last_seen, &has_sequence_naming, &sequence_naming,
        &error);
  }

  if (status != PP_OK) {
    /* Branch on the code; the message is diagnostic text for people. The
     * message is borrowed from the error handle. */
    fprintf(stderr, "operation failed (%u): %s\n", status,
            error != NULL ? pp_error_message(error) : "no details");
  } else {
    print_asset_id(&asset_id);
    printf("representations: %llu\n",
           (unsigned long long)pp_representation_set_count(representations));
    /* Use borrowed strings before releasing the set that owns them. */
    printf("location: %s\n", uri);
  }
  pp_error_release(error);
  pp_representation_set_release(representations);
  pp_transaction_release(transaction);
  pp_production_release(production);
  return status == PP_OK ? 0 : 1;
}

The full contract for every function remains in <postproject/postproject.h>.