Skip to content

Commit

Permalink
Created APIClient and inherited UnixAPIClient (formerly UnixAPI) from it
Browse files Browse the repository at this point in the history
  • Loading branch information
GamePad64 committed Jan 24, 2014
1 parent a3a7df0 commit 1d2abcd
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 17 deletions.
24 changes: 24 additions & 0 deletions src/library/APIClient.cpp
@@ -0,0 +1,24 @@
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "APIClient.h"

namespace p2pnet {
namespace api {

void APIClient::process(APIMessage message) {
log() << message.privkey_cert();
}

} /* namespace api */
} /* namespace p2pnet */
38 changes: 38 additions & 0 deletions src/library/APIClient.h
@@ -0,0 +1,38 @@
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef APICLIENT_H_
#define APICLIENT_H_

#include "../common/Loggable.h"

namespace p2pnet {
namespace api {

class APIClient : protected Loggable {
public:
APIClient();
virtual ~APIClient();

void process(APIMessage message);
void send(APIMessage message) = 0;

void shutdown() = 0;

void connect() = 0;
};

} /* namespace api */
} /* namespace p2pnet */

#endif /* APICLIENT_H_ */
17 changes: 7 additions & 10 deletions src/library/UnixAPI.cpp → src/library/UnixAPIClient.cpp
Expand Up @@ -11,7 +11,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UnixAPI.h"
#include "UnixAPIClient.h"
#include "../common/api/APIMessage.pb.h"
#include "export.h"
#include <list>
Expand All @@ -20,23 +20,20 @@ namespace p2pnet {
namespace api {
namespace unix {

UnixAPI::UnixAPI(boost::asio::io_service& io_service) : socket(io_service) {
socket.assignReceiveHandler(std::bind(&UnixAPI::process, this, std::placeholders::_1));
UnixAPIClient::UnixAPIClient(boost::asio::io_service& io_service) : socket(io_service) {
socket.assignReceiveHandler(std::bind(&UnixAPIClient::process, this, std::placeholders::_1));
socket.assignShutdownHandler([](){});

connect();

socket.startReceive();
}

UnixAPI::~UnixAPI() {}
UnixAPIClient::~UnixAPIClient() {}

void UnixAPI::process(APIMessage message) {
log() << message.DebugString();
}
void UnixAPI::send(APIMessage message) {socket.send(message);}
void UnixAPIClient::send(APIMessage message) {socket.send(message);}

void UnixAPI::connect() {
void UnixAPIClient::connect() {
bool connected = false;

auto path_list = unix::getSocketPathList();
Expand All @@ -54,7 +51,7 @@ void UnixAPI::connect() {
log() << "Connected to daemon on: " << socket_path << std::endl;
}

void UnixAPI::shutdown(){
void UnixAPIClient::shutdown(){
};

}
Expand Down
12 changes: 5 additions & 7 deletions src/library/UnixAPI.h → src/library/UnixAPIClient.h
Expand Up @@ -12,24 +12,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UNIXAPI_H_
#define UNIXAPI_H_
#define UNIXAPICLIENT_H_

#include "../common/api/UnixAPISocket.h"
#include "../common/Loggable.h"

namespace p2pnet {
namespace api {
namespace unix {

class UnixAPI : Loggable {
class UnixAPIClient : public APIClient {
std::string socket_path;

UnixAPISocket socket;
public:
UnixAPI(boost::asio::io_service& io_service);
virtual ~UnixAPI();
UnixAPIClient(boost::asio::io_service& io_service);
virtual ~UnixAPIClient();

void process(APIMessage message);
void send(APIMessage message);

void shutdown();
Expand All @@ -41,4 +39,4 @@ class UnixAPI : Loggable {
} /* namespace api */
} /* namespace p2pnet */

#endif /* UNIXAPI_H_ */
#endif /* UNIXAPICLIENT_H_ */

0 comments on commit 1d2abcd

Please sign in to comment.