[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[]) {
|
int main(int _argc, const char *_argv[]) {
|
||||||
etk::init(_argc, _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);
|
zeus::ServiceType<appl::Calculator, appl::UserManager> serviceInterface(userMng);
|
||||||
serviceInterface.setDescription("Calculator interface");
|
serviceInterface.setDescription("Calculator interface");
|
||||||
serviceInterface.setVersion("0.1.1");
|
serviceInterface.setVersion("0.1.1");
|
||||||
@ -99,7 +99,8 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
APPL_INFO("==================================");
|
APPL_INFO("==================================");
|
||||||
APPL_INFO("== ZEUS test service1 start ==");
|
APPL_INFO("== ZEUS test service1 start ==");
|
||||||
APPL_INFO("==================================");
|
APPL_INFO("==================================");
|
||||||
serviceInterface.connect("serviceTest1");
|
serviceInterface.propertyNameService.set("serviceTest1");
|
||||||
|
serviceInterface.connect();
|
||||||
int32_t iii=0;
|
int32_t iii=0;
|
||||||
while (true) {
|
while (true) {
|
||||||
usleep(1000000);
|
usleep(1000000);
|
||||||
|
@ -394,7 +394,7 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
APPL_INFO("===========================================================");
|
APPL_INFO("===========================================================");
|
||||||
APPL_INFO("== ZEUS instanciate service: " << SERVICE_NAME << " [START]");
|
APPL_INFO("== ZEUS instanciate service: " << SERVICE_NAME << " [START]");
|
||||||
APPL_INFO("===========================================================");
|
APPL_INFO("===========================================================");
|
||||||
appl::UserManager userMng;
|
ememory::SharedPtr<appl::UserManager> userMng = ememory::makeShared<appl::UserManager>();
|
||||||
zeus::ServiceType<appl::PictureService, appl::UserManager> serviceInterface(userMng);
|
zeus::ServiceType<appl::PictureService, appl::UserManager> serviceInterface(userMng);
|
||||||
if (ip != "") {
|
if (ip != "") {
|
||||||
serviceInterface.propertyIp.set(ip);
|
serviceInterface.propertyIp.set(ip);
|
||||||
@ -402,6 +402,7 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
if (port != 0) {
|
if (port != 0) {
|
||||||
serviceInterface.propertyPort.set(port);
|
serviceInterface.propertyPort.set(port);
|
||||||
}
|
}
|
||||||
|
serviceInterface.propertyNameService.set(SERVICE_NAME);
|
||||||
serviceInterface.setDescription("Picture Private Interface");
|
serviceInterface.setDescription("Picture Private Interface");
|
||||||
serviceInterface.setVersion("0.1.0");
|
serviceInterface.setVersion("0.1.0");
|
||||||
serviceInterface.setType("PICTURE", 1);
|
serviceInterface.setType("PICTURE", 1);
|
||||||
@ -419,12 +420,12 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
serviceInterface.advertise("getAlbumPictureGeoLocalization", &appl::PictureService::getAlbumPictureGeoLocalization);
|
serviceInterface.advertise("getAlbumPictureGeoLocalization", &appl::PictureService::getAlbumPictureGeoLocalization);
|
||||||
*/
|
*/
|
||||||
APPL_INFO("===========================================================");
|
APPL_INFO("===========================================================");
|
||||||
APPL_INFO("== ZEUS service: " << SERVICE_NAME << " [service instanciate]");
|
APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [service instanciate]");
|
||||||
APPL_INFO("===========================================================");
|
APPL_INFO("===========================================================");
|
||||||
serviceInterface.connect(SERVICE_NAME);
|
serviceInterface.connect();
|
||||||
if (serviceInterface.GateWayAlive() == false) {
|
if (serviceInterface.GateWayAlive() == false) {
|
||||||
APPL_INFO("===========================================================");
|
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("===========================================================");
|
||||||
APPL_INFO("wait 5 second ...");
|
APPL_INFO("wait 5 second ...");
|
||||||
usleep(5000000);
|
usleep(5000000);
|
||||||
@ -443,7 +444,7 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
}
|
}
|
||||||
serviceInterface.disconnect();
|
serviceInterface.disconnect();
|
||||||
APPL_INFO("===========================================================");
|
APPL_INFO("===========================================================");
|
||||||
APPL_INFO("== ZEUS service: " << SERVICE_NAME << " [STOP] GateWay Stop");
|
APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [STOP] GateWay Stop");
|
||||||
APPL_INFO("===========================================================");
|
APPL_INFO("===========================================================");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -198,7 +198,7 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
APPL_INFO("===========================================================");
|
APPL_INFO("===========================================================");
|
||||||
APPL_INFO("== ZEUS instanciate service: " << SERVICE_NAME << " [START]");
|
APPL_INFO("== ZEUS instanciate service: " << SERVICE_NAME << " [START]");
|
||||||
APPL_INFO("===========================================================");
|
APPL_INFO("===========================================================");
|
||||||
appl::UserManager userMng;
|
ememory::SharedPtr<appl::UserManager> userMng = ememory::makeShared<appl::UserManager>();
|
||||||
zeus::ServiceType<appl::SystemService, appl::UserManager> serviceInterface(userMng);
|
zeus::ServiceType<appl::SystemService, appl::UserManager> serviceInterface(userMng);
|
||||||
if (ip != "") {
|
if (ip != "") {
|
||||||
serviceInterface.propertyIp.set(ip);
|
serviceInterface.propertyIp.set(ip);
|
||||||
@ -206,6 +206,7 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
if (port != 0) {
|
if (port != 0) {
|
||||||
serviceInterface.propertyPort.set(port);
|
serviceInterface.propertyPort.set(port);
|
||||||
}
|
}
|
||||||
|
serviceInterface.propertyNameService.set(SERVICE_NAME);
|
||||||
serviceInterface.setDescription("user interface management");
|
serviceInterface.setDescription("user interface management");
|
||||||
serviceInterface.setVersion("0.1.0");
|
serviceInterface.setVersion("0.1.0");
|
||||||
serviceInterface.setType("USER", 1);
|
serviceInterface.setType("USER", 1);
|
||||||
@ -233,12 +234,12 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
func->addParam("currentList", "Vector of name of the services");
|
func->addParam("currentList", "Vector of name of the services");
|
||||||
}
|
}
|
||||||
APPL_INFO("===========================================================");
|
APPL_INFO("===========================================================");
|
||||||
APPL_INFO("== ZEUS service: " << SERVICE_NAME << " [service instanciate]");
|
APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [service instanciate]");
|
||||||
APPL_INFO("===========================================================");
|
APPL_INFO("===========================================================");
|
||||||
serviceInterface.connect(SERVICE_NAME);
|
serviceInterface.connect();
|
||||||
if (serviceInterface.GateWayAlive() == false) {
|
if (serviceInterface.GateWayAlive() == false) {
|
||||||
APPL_INFO("===========================================================");
|
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("===========================================================");
|
||||||
APPL_INFO("wait 5 second ...");
|
APPL_INFO("wait 5 second ...");
|
||||||
usleep(5000000);
|
usleep(5000000);
|
||||||
@ -253,7 +254,7 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
}
|
}
|
||||||
serviceInterface.disconnect();
|
serviceInterface.disconnect();
|
||||||
APPL_INFO("===========================================================");
|
APPL_INFO("===========================================================");
|
||||||
APPL_INFO("== ZEUS service: " << SERVICE_NAME << " [STOP] GateWay Stop");
|
APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [STOP] GateWay Stop");
|
||||||
APPL_INFO("===========================================================");
|
APPL_INFO("===========================================================");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -13,7 +13,8 @@
|
|||||||
|
|
||||||
zeus::Service::Service() :
|
zeus::Service::Service() :
|
||||||
propertyIp(this, "ip", "127.0.0.1", "Ip to connect server", &zeus::Service::onPropertyChangeIp),
|
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);
|
zeus::AbstractFunction* func = advertise("getExtention", &zeus::Service::getExtention);
|
||||||
if (func != nullptr) {
|
if (func != nullptr) {
|
||||||
func->setDescription("Get List of availlable extention of this service");
|
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() {
|
void zeus::Service::onPropertyChangeIp() {
|
||||||
disconnect();
|
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();
|
disconnect();
|
||||||
ZEUS_DEBUG("connect [START]");
|
ZEUS_DEBUG("connect [START]");
|
||||||
enet::Tcp connection = std::move(enet::connectTcpClient(*propertyIp, *propertyPort, _numberRetry));
|
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->connect(this, &zeus::Service::onClientData);
|
||||||
m_interfaceClient->setInterface(std::move(connection), false);
|
m_interfaceClient->setInterface(std::move(connection), false);
|
||||||
m_interfaceClient->connect();
|
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();
|
ret.wait();
|
||||||
if (ret.get() == false) {
|
if (ret.get() == false) {
|
||||||
ZEUS_ERROR("Can not configure the interface for the service with the current name ...");
|
ZEUS_ERROR("Can not configure the interface for the service with the current name ...");
|
||||||
|
@ -102,6 +102,7 @@ namespace zeus {
|
|||||||
public:
|
public:
|
||||||
eproperty::Value<std::string> propertyIp; //!< Ip of WebSocket TCP connection
|
eproperty::Value<std::string> propertyIp; //!< Ip of WebSocket TCP connection
|
||||||
eproperty::Value<uint16_t> propertyPort; //!< Port of the WebSocket connection
|
eproperty::Value<uint16_t> propertyPort; //!< Port of the WebSocket connection
|
||||||
|
eproperty::Value<std::string> propertyNameService; //!< Service name
|
||||||
protected:
|
protected:
|
||||||
ememory::SharedPtr<zeus::WebServer> m_interfaceClient;
|
ememory::SharedPtr<zeus::WebServer> m_interfaceClient;
|
||||||
uint32_t m_id;
|
uint32_t m_id;
|
||||||
@ -125,7 +126,7 @@ namespace zeus {
|
|||||||
* @param[in]
|
* @param[in]
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void connect(const std::string& _serviceName, uint32_t _numberRetry = 1);
|
void connect(uint32_t _numberRetry = 1);
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* @param[in]
|
* @param[in]
|
||||||
@ -153,6 +154,12 @@ namespace zeus {
|
|||||||
*/
|
*/
|
||||||
bool GateWayAlive();
|
bool GateWayAlive();
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* @param[in]
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void onPropertyChangeServiceName();
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* @param[in]
|
* @param[in]
|
||||||
@ -233,7 +240,7 @@ namespace zeus {
|
|||||||
template<class ZEUS_TYPE_SERVICE, class ZEUS_USER_ACCESS>
|
template<class ZEUS_TYPE_SERVICE, class ZEUS_USER_ACCESS>
|
||||||
class ServiceType : public zeus::Service {
|
class ServiceType : public zeus::Service {
|
||||||
private:
|
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...)
|
// 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;
|
std::map<uint64_t, std::pair<ememory::SharedPtr<ClientProperty>, ememory::SharedPtr<ZEUS_TYPE_SERVICE>>> m_interface;
|
||||||
public:
|
public:
|
||||||
@ -275,7 +282,7 @@ namespace zeus {
|
|||||||
* @param[in]
|
* @param[in]
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ServiceType(ZEUS_USER_ACCESS& _interface):
|
ServiceType(ememory::SharedPtr<ZEUS_USER_ACCESS> _interface):
|
||||||
m_getUserInterface(_interface) {
|
m_getUserInterface(_interface) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -302,7 +309,12 @@ namespace zeus {
|
|||||||
ZEUS_DEBUG(" client name='" << _clientName << "'");
|
ZEUS_DEBUG(" client name='" << _clientName << "'");
|
||||||
ZEUS_DEBUG(" groups=" << etk::to_string(_groups));
|
ZEUS_DEBUG(" groups=" << etk::to_string(_groups));
|
||||||
ememory::SharedPtr<ClientProperty> tmpProperty = ememory::makeShared<ClientProperty>(_clientName, _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)));
|
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) {
|
for (auto &it : m_listFunction) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user