IcePatch2 includes a pair of C++ classes that simplify the task of writing your own patch client, along with a Microsoft Foundation Classes (MFC) example that shows how to use these classes. You can find the MFC example in the subdirectory demo/IcePatch2/MFC of your Ice distribution.

The remainder of this section discusses the classes. To incorporate them into a custom patch client, your program must include the header file IcePatch2/ClientUtil.h and link with the IcePatch2 library.

On this page:

Performing a Patch

The Patcher class encapsulates all of the patching logic required by a client:

{zcode:cpp}
namespace IcePatch2 {
class Patcher : ... {
public:

    Patcher(const Ice::CommunicatorPtr& communicator,
            const PatcherFeedbackPtr& feedback);

    Patcher(const FileServerPrx& server,
            const PatcherFeedbackPtr& feedback,
            const std::string& dataDir, bool thorough,
            Ice::Int chunkSize, Ice::Int remove);

    bool prepare();

    bool patch(const std::string& dir);

    void finish();
};
typedef IceUtil::Handle<Patcher> PatcherPtr;
}
{zcode}

Constructing a Patcher

The constructors provide two ways of configuring a Patcher instance. The first form obtains the following IcePatch2Client configuration properties from the supplied communicator:

The second constructor accepts arguments that correspond to each of these properties.

Both constructors also accept a PatcherFeedback object, which allows the client to monitor the progress of the patch.

Executing the Patch

Patcher provides three methods that reflect the three stages of a patch:

The code below demonstrates a simple patch client:

{zcode:cpp}
#include <IcePatch2/ClientUtil.h>
...
Ice::CommunicatorPtr communicator = ...;
IcePatch2::PatcherFeedbackPtr feedback = new MyPatcherFeedbackI;
IcePatch2::PatcherPtr patcher =
    new IcePatch2::Patcher(communicator, feedback);

try {
    bool aborted = !patcher->prepare();
    if(!aborted)
        aborted = !patcher->patch("");
    if(!aborted)
        patcher->finish();
    if(aborted)
        cerr << "Patch aborted" << endl;
} catch(const string& reason) {
    cerr << "Patch error: " << reason << endl;
}
{zcode}

For a more sophisticated example, see demo/IcePatch2/MFC in your Ice distribution.

Monitoring Patch Progress

The class PatcherFeedback is an abstract base class that allows you to monitor the progress of a Patcher object. The class declaration is shown below:

{zcode:cpp}
namespace IcePatch2 {
class PatcherFeedback : ... {
public:

    virtual bool noFileSummary(const std::string& reason) = 0;

    virtual bool checksumStart() = 0;
    virtual bool checksumProgress(const std::string& path) = 0;
    virtual bool checksumEnd() = 0;

    virtual bool fileListStart() = 0;
    virtual bool fileListProgress(Ice::Int percent) = 0;
    virtual bool fileListEnd() = 0;

    virtual bool patchStart(
        const std::string& path, Ice::Long size,
        Ice::Long updated, Ice::Long total) = 0;
    virtual bool patchProgress(
        Ice::Long pos, Ice::Long size,
        Ice::Long updated, Ice::Long total) = 0;
    virtual bool patchEnd() = 0;
};
typedef IceUtil::Handle<PatcherFeedback> PatcherFeedbackPtr;
}
{zcode}

Each of these methods returns a boolean value:

The methods are described below.

See Also