1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2016 Couchbase, Inc
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  */
17 
18 #pragma once
19 
20 #include "buckets.h"
21 #include "connection.h"
22 #include "memcached.h"
23 #include "memcached/server_api.h"
24 #include "task.h"
25 
26 #include <string>
27 
28 
29 class McbpDestroyBucketTask : public Task {
30 public:
McbpDestroyBucketTask(const std::string& name_, bool force_, Cookie* cookie_)31     McbpDestroyBucketTask(const std::string& name_,
32                           bool force_,
33                           Cookie* cookie_)
34         : thread(name_, force_, cookie_, this) {
35     }
36 
37     // start the bucket deletion
38     // May throw std::bad_alloc if we're failing to start the thread
start()39     void start() {
40         thread.start();
41     }
42 
43     Status execute() override {
44         return Status::Finished;
45     }
46 
47     void notifyExecutionComplete() override {
48         const auto* cookie = thread.getCookie();
49         if (cookie != nullptr) {
50             notify_io_complete(
51                 static_cast<const void*>(cookie), thread.getResult());
52         }
53     }
54 
55 protected:
56     DestroyBucketThread thread;
57 };
58