Add async RPC queue and operation classes.

Add z_getoperationstatus RPC command.
Add z_sendmany RPC command (dummy implementation, does not send actual
coins).
This commit is contained in:
Simon
2016-08-16 10:33:04 -07:00
parent 289b12e448
commit fc72c078be
11 changed files with 843 additions and 0 deletions

61
src/asyncrpcqueue.h Normal file
View File

@@ -0,0 +1,61 @@
// Copyright (c) 2014 The Zcash developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef ASYNCRPCQUEUE_H
#define ASYNCRPCQUEUE_H
#include "asyncrpcoperation.h"
#include <iostream>
#include <string>
#include <chrono>
#include <queue>
#include <unordered_map>
#include <vector>
#include <future>
#include <thread>
#include <utility>
#include <memory>
typedef std::unordered_map<AsyncRPCOperationId, std::shared_ptr<AsyncRPCOperation> > AsyncRPCOperationMap;
class AsyncRPCQueue {
public:
AsyncRPCQueue();
virtual ~AsyncRPCQueue();
// We don't want queue to be copied or moved around
AsyncRPCQueue(AsyncRPCQueue const&) = delete; // Copy construct
AsyncRPCQueue(AsyncRPCQueue&&) = delete; // Move construct
AsyncRPCQueue& operator=(AsyncRPCQueue const&) = delete; // Copy assign
AsyncRPCQueue& operator=(AsyncRPCQueue &&) = delete; // Move assign
void addWorker();
int getNumberOfWorkers();
bool isClosed();
void close();
void cancelAllOperations();
int getOperationCount();
std::shared_ptr<AsyncRPCOperation> getOperationForId(AsyncRPCOperationId);
std::shared_ptr<AsyncRPCOperation> popOperationForId(AsyncRPCOperationId);
void addOperation(const std::shared_ptr<AsyncRPCOperation> &ptrOperation);
private:
// addWorker() will spawn a new thread on this method
void run(int workerId);
std::mutex cs_lock;
std::condition_variable cs_condition;
bool closed;
AsyncRPCOperationMap operationMap;
std::queue <AsyncRPCOperationId> operationIdQueue;
std::vector<std::thread> workers;
};
#endif