Skip to content

Commit

Permalink
Renamed service namespace to endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
GamePad64 committed Jan 10, 2014
1 parent 2fb6728 commit 43244e1
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 139 deletions.
Expand Up @@ -11,19 +11,24 @@
* 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 "ServiceManager.h"
#include "EndpointManager.h"

namespace p2pnet {
namespace service {
namespace endpoint {

ServiceManager::ServiceManager() {
EndpointManager::EndpointManager() {
// TODO Auto-generated constructor stub

}

ServiceManager::~ServiceManager() {
EndpointManager::~EndpointManager() {
// TODO Auto-generated destructor stub
}

} /* namespace service */
std::shared_ptr< LocalEndpoint > EndpointManager::getEndpointPtrBySH(SH sh) {
auto endp_it = sh_all_endpoints.find(sh);
return (endp_it == sh_all_endpoints.end()) ? nullptr : endp_it->second;
}

} /* namespace endpoint */
} /* namespace p2pnet */
Expand Up @@ -11,26 +11,31 @@
* 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 "LocalService.h"
#ifndef ENDPOINTMANAGER_H_
#define ENDPOINTMANAGER_H_

namespace p2pnet {
namespace service {
#include "../../common/Singleton.h"
#include "../../common/Loggable.h"
#include "SH.h"

#include <memory>
#include <map>

LocalService::LocalService(service_type type) {
this->type = type;
this->api_service_ptr = nullptr;
}
namespace p2pnet {
namespace endpoint {

LocalService::LocalService(service_type type, api::APIService* api_service_ptr) {
this->type = type;
this->api_service_ptr = api_service_ptr;
}
class LocalEndpoint;

LocalService::~LocalService() {}
class EndpointManager : public Singleton<EndpointManager>, Loggable {
std::map<SH, std::shared_ptr<LocalEndpoint>> sh_all_endpoints;
public:
EndpointManager();
virtual ~EndpointManager();

SH LocalService::getSH() const {
return SH(private_key.derivePublicKey());
}
std::shared_ptr<LocalEndpoint> getEndpointPtrBySH(SH sh);
};

} /* namespace service */
} /* namespace endpoint */
} /* namespace p2pnet */

#endif /* ENDPOINTMANAGER_H_ */
Expand Up @@ -11,19 +11,29 @@
* 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 "StandardService.h"
#include "LocalEndpoint.h"
#include "EndpointManager.h"

namespace p2pnet {
namespace service {
namespace endpoint {

LocalEndpoint::LocalEndpoint() {
// TODO Auto-generated constructor stub

StandardService::StandardService() : LocalService(STANDARD) {
}

StandardService::StandardService(api::APIService* api_service_ptr) : LocalService(STANDARD, api_service_ptr) {
LocalEndpoint::~LocalEndpoint() {
// TODO Auto-generated destructor stub
}

StandardService::~StandardService() {
bool LocalEndpoint::trySendLoopback(SH dest, std::string data) {
auto endpoint_ptr = EndpointManager::getInstance()->getEndpointPtrBySH(dest);
if(getValue<bool>("endpoint.allow_loopback") && endpoint_ptr){
endpoint_ptr->process(endpoint_sh, data);
return true;
}
return false;
}

} /* namespace service */
} /* namespace endpoint */
} /* namespace p2pnet */
Expand Up @@ -11,22 +11,30 @@
* 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 STANDARDSERVICE_H_
#define STANDARDSERVICE_H_
#ifndef LOCALENDPOINT_H_
#define LOCALENDPOINT_H_

#include "LocalService.h"
#include "../../common/Config.h"
#include "SH.h"

namespace p2pnet {
namespace service {
namespace endpoint {

class StandardService : public p2pnet::service::LocalService {
class LocalEndpoint : ConfigClient {
SH endpoint_sh;
public:
StandardService();
StandardService(api::APIService* api_service_ptr);
virtual ~StandardService();
LocalEndpoint();
virtual ~LocalEndpoint();

virtual void send(SH dest, std::string data) = 0;
virtual void process(SH from, std::string data) = 0;

bool trySendLoopback(SH dest, std::string data);

SH getSH(){return endpoint_sh;};
};

} /* namespace service */
} /* namespace endpoint */
} /* namespace p2pnet */

#endif /* STANDARDSERVICE_H_ */
#endif /* LOCALENDPOINT_H_ */
4 changes: 2 additions & 2 deletions src/daemon/service/SH.h → src/daemon/endpoint/SH.h
Expand Up @@ -18,11 +18,11 @@
#include "../../common/crypto/Hash.h"

namespace p2pnet {
namespace service {
namespace endpoint {

typedef crypto::Hash SH;

} /* namespace service */
} /* namespace endpoint */
} /* namespace p2pnet */

#endif /* SH_H_ */
53 changes: 0 additions & 53 deletions src/daemon/service/LocalService.h

This file was deleted.

47 changes: 0 additions & 47 deletions src/daemon/service/ServiceManager.h

This file was deleted.

0 comments on commit 43244e1

Please sign in to comment.