// AddShare // // The caller gets a reference, if _share is not NULL. status_t SecurityContext::AddShare(const char* name, const char* path, Share** _share) { if (!name) return B_BAD_VALUE; // check, if the share does already exist ContextLocker _(this); if (fShares->Get(name)) return B_BAD_VALUE; // create a the share Share* share = new(std::nothrow) Share; if (!share) return B_NO_MEMORY; Reference<Share> shareReference(share, true); status_t error = share->Init(name, path); if (error != B_OK) return error; // add the share error = fShares->Put(name, share); if (error != B_OK) return error; shareReference.Detach(); if (_share) { *_share = share; share->AddReference(); } return B_OK; }
// FindShare // // The caller gets a reference. Share* SecurityContext::FindShare(const char* name) { if (!name) return NULL; ContextLocker _(this); Share* share = fShares->Get(name); if (share) share->AddReference(); return share; }
// RemoveShare // // The caller gets a reference, if _share is not NULL. status_t SecurityContext::RemoveShare(const char* name, Share** _share) { if (!name) return B_BAD_VALUE; ContextLocker _(this); // get the share Share* share = FindShare(name); if (!share) return B_ENTRY_NOT_FOUND; Reference<Share> shareReference(share, true); // remove it status_t error = RemoveShare(share); if (error == B_OK && _share) { *_share = share; share->AddReference(); } return error; }