Table of Contents

More complex examples:

  • msynctool - The command line client of multisync
  • convcard - A tool to convert vcard between version 3.0 and 2.1. It uses the conversion subsystem of OpenSync

Note: All examples can be compiled using: gcc test.c $(pkg-config --cflags --libs opensync) $(pkg-config --libs osengine)

Listing all Plugins:

#include <opensync/opensync.h>

int main(int argc, char *argv[])
{
    int i;
    OSyncPlugin *plugin;        

    /* We make a new environment that will hold our plugins, groups etc
     * and initialize it
     */
    OSyncEnv *env = osync_env_new();
    osync_env_initialize(env, NULL);

    /* Now we can iterate over the available plugins and print their names */
    for (i = 0; i < osync_env_num_plugins(env); i++)
    {
        plugin = osync_env_nth_plugin(env, i);
        printf("%s\n", osync_plugin_get_name(plugin));
    }

    /* Some cleanup */
    osync_env_finalize(env, NULL);
    osync_env_free(env);
    return 0;
}

Synchronizing a group:

#include <opensync/opensync.h>
#include <opensync/engine.h>

int main(int argc, char *argv[])
{
    /* We make a new environment that will hold our plugins, groups etc
     * and initialize it
     */
    OSyncEnv *env = osync_env_new();
    osync_env_initialize(env, NULL);

    /* Now we can load the group from a directory */
    OSyncGroup *group = osync_group_load(env, "<directory of group> for example: /home/joe/.opensync/group1", NULL);

    /* We make a new synchronization engine for this group and initialize it
     * Note that in this example, there is no error checking
     */
    OSyncEngine *engine = osync_engine_new(group, NULL);
    osync_engine_init(engine, NULL);

    /* Now we synchronize using the engine. This function will normally
     * return TRUE or FALSE wether the sync was successfull or not.
     * This function will block until the synchronization has ended.
     */
    osync_engine_sync_and_block(engine, NULL);

    /* Some cleanup */
    osync_engine_finalize(engine);
    osync_engine_free(engine);

    osync_env_finalize(env, NULL);
    osync_env_free(env);
    return 0;
}