Skip to content

Implementing a backend

hbons edited this page Feb 9, 2012 · 32 revisions

Implementing a backend

By default, SparkleShare uses Git to store and sync files. However, you can implement a custom backend to suit your needs with relative ease. It's possible to use an other version control system or some other custom protocol. This page tries to explain how to go about this.

Overview

There are two abstract classes that need extending to get a working backend:

  • SparkleFetcherBase takes care of the initial fetching of a remote repository,
  • SparkleRepoBase implements the syncing algorithm and handles notifications between clients.

Here's an overview of all the members that need an implementation:

SparkleRepoBase

// Constructors
public SparkleRepoGit (string path);

// Methods
public abstract bool SyncUp ();
public abstract bool SyncDown ();
public abstract List<SparkleChangeSet> GetChangeSets (int count);
protected void OnProgressChanged (double progress_percentage, string progress_speed);

// Properties
public abstract string Identifier { get; }
public abstract string CurrentRevision { get; }
public abstract bool HasRemoteChanges { get; }
public abstract bool HasLocalChanges { get; }
public abstract double Size { get; }
public abstract double HistorySize { get; }

SparkleFetcherBase

// Constructors
public SparkleFetcherBase (string server, string remote_folder, string target_folder);

// Methods
public abstract bool Fetch ();
public abstract void Stop ();
protected void OnProgressChanged (double percentage);

// Properties
public abstract string [] Warnings { get; }

Getting started

Put your files in SparkleLib/. You can create a subdirectory for your backend if you want like the default backend Git/. Just make sure the files are added to the Makefile.am file for compilation.

It's important that your files and classes are named properly. For example: if your backend is called hg, then name your extended classes SparkleRepoHg and SparkleFetcherHg.

Notes

All implemented members need to be blocking/synchronous.

Testing

You can specify a backend type to use by appending it's name to the Remote Path value in the Add Hosted Project dialog. For example:

  • /home/project.git uses the classes SparkleRepoGit, SparkleFetcherGit as its backend
  • /home/project.hg uses the classes SparkleRepoHg, SparkleFetcherHg as its backend