Skip to content

Commit

Permalink
Allow constructing a BackupProtocolLocal with an existing BackupStore…
Browse files Browse the repository at this point in the history
…Context.

Together with previous changes to BackupStoreContext, this allows the use of
BackupProtocolLocal with S3BackupFileSystem, mainly for testing.
  • Loading branch information
qris committed Nov 27, 2015
1 parent 1c708be commit 882c246
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
35 changes: 24 additions & 11 deletions lib/backupstore/BackupProtocol.h
Expand Up @@ -25,27 +25,40 @@
class BackupProtocolLocal2 : public BackupProtocolLocal
{
private:
BackupStoreContext mContext;
std::auto_ptr<BackupStoreContext> mapLocalContext;
int32_t mAccountNumber;
bool mReadOnly;

protected:
BackupStoreContext& GetContext() { return mContext; }

public:
BackupProtocolLocal2(int32_t AccountNumber,
const std::string& ConnectionDetails,
const std::string& AccountRootDir, int DiscSetNumber,
bool ReadOnly)
// This is rather ugly: the BackupProtocolLocal constructor must not
// touch the Context, because it's not initialised yet!
: BackupProtocolLocal(mContext),
mContext(AccountNumber, (HousekeepingInterface *)NULL,
ConnectionDetails),
// This is rather ugly: we need to pass a reference to a context to
// BackupProtocolLocal(), and we want it to be one that we've created ourselves,
// so we create one with new(), dereference it to pass the reference to the
// superclass, and then get the reference out again, take its address and stick
// that into the auto_ptr, which will delete it when we are destroyed.
: BackupProtocolLocal(
*(new BackupStoreContext(AccountNumber, (HousekeepingInterface *)NULL,
ConnectionDetails))
),
mapLocalContext(&GetContext()),
mAccountNumber(AccountNumber),
mReadOnly(ReadOnly)
{
GetContext().SetClientHasAccount(AccountRootDir, DiscSetNumber);
QueryVersion(BACKUP_STORE_SERVER_VERSION);
QueryLogin(AccountNumber,
ReadOnly ? BackupProtocolLogin::Flags_ReadOnly : 0);
}
BackupProtocolLocal2(BackupStoreContext& rContext, int32_t AccountNumber,
bool ReadOnly)
: BackupProtocolLocal(rContext),
mAccountNumber(AccountNumber),
mReadOnly(ReadOnly)
{
mContext.SetClientHasAccount(AccountRootDir, DiscSetNumber);
GetContext().SetClientHasAccount();
QueryVersion(BACKUP_STORE_SERVER_VERSION);
QueryLogin(AccountNumber,
ReadOnly ? BackupProtocolLogin::Flags_ReadOnly : 0);
Expand All @@ -56,7 +69,7 @@ class BackupProtocolLocal2 : public BackupProtocolLocal
{
std::auto_ptr<BackupProtocolFinished> finished =
BackupProtocolLocal::Query(rQuery);
mContext.ReleaseWriteLock();
GetContext().ReleaseWriteLock();
return finished;
}

Expand Down
7 changes: 7 additions & 0 deletions lib/server/makeprotocol.pl.in
Expand Up @@ -887,6 +887,13 @@ __E
private:
$context_class &mrContext;
std::auto_ptr<$message_base_class> mapLastReply;

protected:
$context_class& GetContext()
{
return mrContext;
}

public:
virtual std::auto_ptr<IOStream> ReceiveStream()
{
Expand Down

0 comments on commit 882c246

Please sign in to comment.