[DEV] update the API of user interface
This commit is contained in:
parent
fa702798cb
commit
185c427453
@ -70,7 +70,7 @@ namespace appl {
|
||||
|
||||
int main(int _argc, const char *_argv[]) {
|
||||
etk::init(_argc, _argv);
|
||||
appl::UserManager userMng;
|
||||
ememory::SharedPtr<appl::UserManager> userMng = ememory::makeShared<appl::UserManager>();
|
||||
zeus::ServiceType<appl::Calculator, appl::UserManager> serviceInterface(userMng);
|
||||
serviceInterface.setDescription("Calculator interface");
|
||||
serviceInterface.setVersion("0.1.1");
|
||||
@ -99,7 +99,8 @@ int main(int _argc, const char *_argv[]) {
|
||||
APPL_INFO("==================================");
|
||||
APPL_INFO("== ZEUS test service1 start ==");
|
||||
APPL_INFO("==================================");
|
||||
serviceInterface.connect("serviceTest1");
|
||||
serviceInterface.propertyNameService.set("serviceTest1");
|
||||
serviceInterface.connect();
|
||||
int32_t iii=0;
|
||||
while (true) {
|
||||
usleep(1000000);
|
||||
|
@ -394,7 +394,7 @@ int main(int _argc, const char *_argv[]) {
|
||||
APPL_INFO("===========================================================");
|
||||
APPL_INFO("== ZEUS instanciate service: " << SERVICE_NAME << " [START]");
|
||||
APPL_INFO("===========================================================");
|
||||
appl::UserManager userMng;
|
||||
ememory::SharedPtr<appl::UserManager> userMng = ememory::makeShared<appl::UserManager>();
|
||||
zeus::ServiceType<appl::PictureService, appl::UserManager> serviceInterface(userMng);
|
||||
if (ip != "") {
|
||||
serviceInterface.propertyIp.set(ip);
|
||||
@ -402,6 +402,7 @@ int main(int _argc, const char *_argv[]) {
|
||||
if (port != 0) {
|
||||
serviceInterface.propertyPort.set(port);
|
||||
}
|
||||
serviceInterface.propertyNameService.set(SERVICE_NAME);
|
||||
serviceInterface.setDescription("Picture Private Interface");
|
||||
serviceInterface.setVersion("0.1.0");
|
||||
serviceInterface.setType("PICTURE", 1);
|
||||
@ -419,12 +420,12 @@ int main(int _argc, const char *_argv[]) {
|
||||
serviceInterface.advertise("getAlbumPictureGeoLocalization", &appl::PictureService::getAlbumPictureGeoLocalization);
|
||||
*/
|
||||
APPL_INFO("===========================================================");
|
||||
APPL_INFO("== ZEUS service: " << SERVICE_NAME << " [service instanciate]");
|
||||
APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [service instanciate]");
|
||||
APPL_INFO("===========================================================");
|
||||
serviceInterface.connect(SERVICE_NAME);
|
||||
serviceInterface.connect();
|
||||
if (serviceInterface.GateWayAlive() == false) {
|
||||
APPL_INFO("===========================================================");
|
||||
APPL_INFO("== ZEUS service: " << SERVICE_NAME << " [STOP] Can not connect to the GateWay");
|
||||
APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [STOP] Can not connect to the GateWay");
|
||||
APPL_INFO("===========================================================");
|
||||
APPL_INFO("wait 5 second ...");
|
||||
usleep(5000000);
|
||||
@ -443,7 +444,7 @@ int main(int _argc, const char *_argv[]) {
|
||||
}
|
||||
serviceInterface.disconnect();
|
||||
APPL_INFO("===========================================================");
|
||||
APPL_INFO("== ZEUS service: " << SERVICE_NAME << " [STOP] GateWay Stop");
|
||||
APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [STOP] GateWay Stop");
|
||||
APPL_INFO("===========================================================");
|
||||
}
|
||||
return 0;
|
||||
|
@ -198,7 +198,7 @@ int main(int _argc, const char *_argv[]) {
|
||||
APPL_INFO("===========================================================");
|
||||
APPL_INFO("== ZEUS instanciate service: " << SERVICE_NAME << " [START]");
|
||||
APPL_INFO("===========================================================");
|
||||
appl::UserManager userMng;
|
||||
ememory::SharedPtr<appl::UserManager> userMng = ememory::makeShared<appl::UserManager>();
|
||||
zeus::ServiceType<appl::SystemService, appl::UserManager> serviceInterface(userMng);
|
||||
if (ip != "") {
|
||||
serviceInterface.propertyIp.set(ip);
|
||||
@ -206,6 +206,7 @@ int main(int _argc, const char *_argv[]) {
|
||||
if (port != 0) {
|
||||
serviceInterface.propertyPort.set(port);
|
||||
}
|
||||
serviceInterface.propertyNameService.set(SERVICE_NAME);
|
||||
serviceInterface.setDescription("user interface management");
|
||||
serviceInterface.setVersion("0.1.0");
|
||||
serviceInterface.setType("USER", 1);
|
||||
@ -233,12 +234,12 @@ int main(int _argc, const char *_argv[]) {
|
||||
func->addParam("currentList", "Vector of name of the services");
|
||||
}
|
||||
APPL_INFO("===========================================================");
|
||||
APPL_INFO("== ZEUS service: " << SERVICE_NAME << " [service instanciate]");
|
||||
APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [service instanciate]");
|
||||
APPL_INFO("===========================================================");
|
||||
serviceInterface.connect(SERVICE_NAME);
|
||||
serviceInterface.connect();
|
||||
if (serviceInterface.GateWayAlive() == false) {
|
||||
APPL_INFO("===========================================================");
|
||||
APPL_INFO("== ZEUS service: " << SERVICE_NAME << " [STOP] Can not connect to the GateWay");
|
||||
APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [STOP] Can not connect to the GateWay");
|
||||
APPL_INFO("===========================================================");
|
||||
APPL_INFO("wait 5 second ...");
|
||||
usleep(5000000);
|
||||
@ -253,7 +254,7 @@ int main(int _argc, const char *_argv[]) {
|
||||
}
|
||||
serviceInterface.disconnect();
|
||||
APPL_INFO("===========================================================");
|
||||
APPL_INFO("== ZEUS service: " << SERVICE_NAME << " [STOP] GateWay Stop");
|
||||
APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [STOP] GateWay Stop");
|
||||
APPL_INFO("===========================================================");
|
||||
}
|
||||
return 0;
|
||||
|
@ -13,7 +13,8 @@
|
||||
|
||||
zeus::Service::Service() :
|
||||
propertyIp(this, "ip", "127.0.0.1", "Ip to connect server", &zeus::Service::onPropertyChangeIp),
|
||||
propertyPort(this, "port", 1982, "Port to connect server", &zeus::Service::onPropertyChangePort) {
|
||||
propertyPort(this, "port", 1982, "Port to connect server", &zeus::Service::onPropertyChangePort),
|
||||
propertyNameService(this, "name", "no-name", "Sevice name", &zeus::Service::onPropertyChangeServiceName) {
|
||||
zeus::AbstractFunction* func = advertise("getExtention", &zeus::Service::getExtention);
|
||||
if (func != nullptr) {
|
||||
func->setDescription("Get List of availlable extention of this service");
|
||||
@ -68,6 +69,9 @@ void zeus::Service::onClientData(ememory::SharedPtr<zeus::Buffer> _value) {
|
||||
}
|
||||
}
|
||||
|
||||
void zeus::Service::onPropertyChangeServiceName() {
|
||||
disconnect();
|
||||
}
|
||||
void zeus::Service::onPropertyChangeIp() {
|
||||
disconnect();
|
||||
}
|
||||
@ -77,7 +81,7 @@ void zeus::Service::onPropertyChangePort(){
|
||||
}
|
||||
|
||||
|
||||
void zeus::Service::connect(const std::string& _serviceName, uint32_t _numberRetry){
|
||||
void zeus::Service::connect(uint32_t _numberRetry){
|
||||
disconnect();
|
||||
ZEUS_DEBUG("connect [START]");
|
||||
enet::Tcp connection = std::move(enet::connectTcpClient(*propertyIp, *propertyPort, _numberRetry));
|
||||
@ -93,7 +97,7 @@ void zeus::Service::connect(const std::string& _serviceName, uint32_t _numberRet
|
||||
m_interfaceClient->connect(this, &zeus::Service::onClientData);
|
||||
m_interfaceClient->setInterface(std::move(connection), false);
|
||||
m_interfaceClient->connect();
|
||||
zeus::Future<bool> ret = m_interfaceClient->call("connect-service", _serviceName);
|
||||
zeus::Future<bool> ret = m_interfaceClient->call("connect-service", propertyNameService.get());
|
||||
ret.wait();
|
||||
if (ret.get() == false) {
|
||||
ZEUS_ERROR("Can not configure the interface for the service with the current name ...");
|
||||
|
@ -102,6 +102,7 @@ namespace zeus {
|
||||
public:
|
||||
eproperty::Value<std::string> propertyIp; //!< Ip of WebSocket TCP connection
|
||||
eproperty::Value<uint16_t> propertyPort; //!< Port of the WebSocket connection
|
||||
eproperty::Value<std::string> propertyNameService; //!< Service name
|
||||
protected:
|
||||
ememory::SharedPtr<zeus::WebServer> m_interfaceClient;
|
||||
uint32_t m_id;
|
||||
@ -125,7 +126,7 @@ namespace zeus {
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void connect(const std::string& _serviceName, uint32_t _numberRetry = 1);
|
||||
void connect(uint32_t _numberRetry = 1);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
@ -153,6 +154,12 @@ namespace zeus {
|
||||
*/
|
||||
bool GateWayAlive();
|
||||
private:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void onPropertyChangeServiceName();
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
@ -233,7 +240,7 @@ namespace zeus {
|
||||
template<class ZEUS_TYPE_SERVICE, class ZEUS_USER_ACCESS>
|
||||
class ServiceType : public zeus::Service {
|
||||
private:
|
||||
ZEUS_USER_ACCESS& m_getUserInterface;
|
||||
ememory::SharedPtr<ZEUS_USER_ACCESS> m_getUserInterface;
|
||||
// no need of shared_ptr or unique_ptr (if service die all is lost and is client die, the gateway notify us...)
|
||||
std::map<uint64_t, std::pair<ememory::SharedPtr<ClientProperty>, ememory::SharedPtr<ZEUS_TYPE_SERVICE>>> m_interface;
|
||||
public:
|
||||
@ -275,7 +282,7 @@ namespace zeus {
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
ServiceType(ZEUS_USER_ACCESS& _interface):
|
||||
ServiceType(ememory::SharedPtr<ZEUS_USER_ACCESS> _interface):
|
||||
m_getUserInterface(_interface) {
|
||||
|
||||
}
|
||||
@ -302,9 +309,14 @@ namespace zeus {
|
||||
ZEUS_DEBUG(" client name='" << _clientName << "'");
|
||||
ZEUS_DEBUG(" groups=" << etk::to_string(_groups));
|
||||
ememory::SharedPtr<ClientProperty> tmpProperty = ememory::makeShared<ClientProperty>(_clientName, _groups);
|
||||
ememory::SharedPtr<ZEUS_TYPE_SERVICE> tmpSrv = ememory::makeShared<ZEUS_TYPE_SERVICE>(m_getUserInterface.getUser(_userName), tmpProperty);
|
||||
ememory::SharedPtr<ZEUS_TYPE_SERVICE> tmpSrv;
|
||||
if (m_getUserInterface == nullptr) {
|
||||
tmpSrv = ememory::makeShared<ZEUS_TYPE_SERVICE>(tmpProperty);
|
||||
} else {
|
||||
tmpSrv = ememory::makeShared<ZEUS_TYPE_SERVICE>(m_getUserInterface->getUser(_userName), tmpProperty);
|
||||
}
|
||||
m_interface.insert(std::make_pair(_clientId, std::make_pair(tmpProperty, tmpSrv)));
|
||||
// enable list of function availlable:
|
||||
// enable list of function availlable:
|
||||
for (auto &it : m_listFunction) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user