[DEV] add wait for service (2sec) and api to get list of service availlable
This commit is contained in:
parent
abb81cd61a
commit
6091275c64
@ -381,10 +381,10 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
APPL_INFO(" ----------------------------------");
|
APPL_INFO(" ----------------------------------");
|
||||||
APPL_INFO(" -- Get service count");
|
APPL_INFO(" -- Get service count");
|
||||||
APPL_INFO(" ----------------------------------");
|
APPL_INFO(" ----------------------------------");
|
||||||
zeus::Future<int32_t> retNbService = client1.call(ZEUS_NO_ID_OBJECT, ZEUS_ID_GATEWAY, "getServiceCount");
|
zeus::Future<int32_t> retNbService = client1.getServiceCount();
|
||||||
|
zeus::Future<std::vector<std::string>> retServiceList = client1.getServiceList();
|
||||||
retNbService.wait();
|
retNbService.wait();
|
||||||
APPL_INFO("Nb services = " << retNbService.get());
|
APPL_INFO("Nb services = " << retNbService.get());
|
||||||
zeus::Future<std::vector<std::string>> retServiceList = client1.call(ZEUS_NO_ID_OBJECT, ZEUS_ID_GATEWAY, "getServiceList");
|
|
||||||
retServiceList.wait();
|
retServiceList.wait();
|
||||||
APPL_INFO("List services:");
|
APPL_INFO("List services:");
|
||||||
for (auto &it: retServiceList.get()) {
|
for (auto &it: retServiceList.get()) {
|
||||||
@ -398,7 +398,9 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (false) {
|
if ( client1.waitForService("user") == true
|
||||||
|
&& false) {
|
||||||
|
|
||||||
APPL_INFO(" ----------------------------------");
|
APPL_INFO(" ----------------------------------");
|
||||||
APPL_INFO(" -- Get service system-user");
|
APPL_INFO(" -- Get service system-user");
|
||||||
APPL_INFO(" ----------------------------------");
|
APPL_INFO(" ----------------------------------");
|
||||||
@ -446,7 +448,8 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
APPL_INFO(" ----------------------------------");
|
APPL_INFO(" ----------------------------------");
|
||||||
APPL_INFO(" -- Get service picture");
|
APPL_INFO(" -- Get service picture");
|
||||||
APPL_INFO(" ----------------------------------");
|
APPL_INFO(" ----------------------------------");
|
||||||
if (false) {
|
if ( client1.waitForService("picture") == true
|
||||||
|
&& false) {
|
||||||
zeus::service::ProxyPicture remoteServicePicture = client1.getService("picture");
|
zeus::service::ProxyPicture remoteServicePicture = client1.getService("picture");
|
||||||
if (remoteServicePicture.exist() == true) {
|
if (remoteServicePicture.exist() == true) {
|
||||||
// Send a full path:
|
// Send a full path:
|
||||||
@ -455,7 +458,8 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
APPL_ERROR("Can not get service Picture ...");
|
APPL_ERROR("Can not get service Picture ...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (false) {
|
if ( client1.waitForService("picture") == true
|
||||||
|
&& false) {
|
||||||
zeus::service::ProxyPicture remoteServicePicture = client1.getService("picture");
|
zeus::service::ProxyPicture remoteServicePicture = client1.getService("picture");
|
||||||
if (remoteServicePicture.exist() == true) {
|
if (remoteServicePicture.exist() == true) {
|
||||||
zeus::Future<std::vector<uint32_t>> retCall = remoteServicePicture.albumGetList().wait();
|
zeus::Future<std::vector<uint32_t>> retCall = remoteServicePicture.albumGetList().wait();
|
||||||
@ -505,7 +509,8 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
APPL_INFO(" ----------------------------------");
|
APPL_INFO(" ----------------------------------");
|
||||||
APPL_INFO(" -- Get service video (send DATA) ");
|
APPL_INFO(" -- Get service video (send DATA) ");
|
||||||
APPL_INFO(" ----------------------------------");
|
APPL_INFO(" ----------------------------------");
|
||||||
if (true) {
|
if ( client1.waitForService("video") == true
|
||||||
|
&& true) {
|
||||||
zeus::service::ProxyVideo remoteServiceVideo = client1.getService("video");
|
zeus::service::ProxyVideo remoteServiceVideo = client1.getService("video");
|
||||||
// remove all media (for test)
|
// remove all media (for test)
|
||||||
if (remoteServiceVideo.exist() == true) {
|
if (remoteServiceVideo.exist() == true) {
|
||||||
|
@ -35,20 +35,22 @@ typedef zeus::Object* (*SERVICE_IO_instanciate_t)(uint32_t, ememory::SharedPtr<z
|
|||||||
class PlugginAccess {
|
class PlugginAccess {
|
||||||
private:
|
private:
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
std::string m_fullName;
|
||||||
void* m_handle;
|
void* m_handle;
|
||||||
SERVICE_IO_init_t m_SERVICE_IO_init;
|
SERVICE_IO_init_t m_SERVICE_IO_init;
|
||||||
SERVICE_IO_uninit_t m_SERVICE_IO_uninit;
|
SERVICE_IO_uninit_t m_SERVICE_IO_uninit;
|
||||||
SERVICE_IO_peridic_call_t m_SERVICE_IO_peridic_call;
|
SERVICE_IO_peridic_call_t m_SERVICE_IO_peridic_call;
|
||||||
SERVICE_IO_instanciate_t m_SERVICE_IO_instanciate;
|
SERVICE_IO_instanciate_t m_SERVICE_IO_instanciate;
|
||||||
public:
|
public:
|
||||||
PlugginAccess(const std::string& _name) :
|
PlugginAccess(const std::string& _name, const std::string& _fullName) :
|
||||||
m_name(_name),
|
m_name(_name),
|
||||||
|
m_fullName(_fullName),
|
||||||
m_handle(nullptr),
|
m_handle(nullptr),
|
||||||
m_SERVICE_IO_init(nullptr),
|
m_SERVICE_IO_init(nullptr),
|
||||||
m_SERVICE_IO_uninit(nullptr),
|
m_SERVICE_IO_uninit(nullptr),
|
||||||
m_SERVICE_IO_instanciate(nullptr) {
|
m_SERVICE_IO_instanciate(nullptr) {
|
||||||
std::string srv = etk::FSNodeGetApplicationPath() + "/../lib/libzeus-service-" + m_name + "-impl.so";
|
std::string srv = etk::FSNodeGetApplicationPath() + "/../lib/lib" + m_fullName + "-impl.so";
|
||||||
APPL_PRINT("Try to open service with name: '" << m_name << "' at position: '" << srv << "'");
|
APPL_PRINT("Try to open service with name: '" << m_name << "' at position: '" << srv << "' with full name=" << m_fullName);
|
||||||
m_handle = dlopen(srv.c_str(), RTLD_LAZY);
|
m_handle = dlopen(srv.c_str(), RTLD_LAZY);
|
||||||
if (!m_handle) {
|
if (!m_handle) {
|
||||||
APPL_ERROR("Can not load Lbrary:" << dlerror());
|
APPL_ERROR("Can not load Lbrary:" << dlerror());
|
||||||
@ -199,6 +201,35 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef GATEWAY_ENABLE_LAUNCHER
|
||||||
|
std::vector<std::pair<std::string,std::string>> listAvaillableServices;
|
||||||
|
if (services.size() != 0) {
|
||||||
|
// find all services:
|
||||||
|
etk::FSNode dataPath(etk::FSNodeGetApplicationPath() + "/../share");
|
||||||
|
std::vector<std::string> listSubPath = dataPath.folderGetSub(true, false, ".*");
|
||||||
|
APPL_DEBUG(" Base data path: " << dataPath.getName());
|
||||||
|
APPL_DEBUG(" SubPath: " << listSubPath);
|
||||||
|
for (auto &it: listSubPath) {
|
||||||
|
if (etk::FSNodeExist(it + "/zeus/") == true) {
|
||||||
|
etk::FSNode dataPath(it + "/zeus/");
|
||||||
|
std::vector<std::string> listServices = dataPath.folderGetSub(false, true, ".*\\.srv");
|
||||||
|
for (auto &it2: listServices) {
|
||||||
|
std::string nameFileSrv = etk::FSNode(it2).getNameFile();
|
||||||
|
std::vector<std::string> spl = etk::split(std::string(nameFileSrv.begin(), nameFileSrv.end()-4), "-service-");
|
||||||
|
if (spl.size() != 2) {
|
||||||
|
APPL_ERROR("reject service, wrong format ... '" << it2 << "' missing XXX-service-SERVICE-NAME.srv");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
APPL_INFO("find service : " << it2);
|
||||||
|
listAvaillableServices.push_back(std::make_pair(spl[1], std::string(nameFileSrv.begin(), nameFileSrv.end()-4)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// not check the second path ==> no service availlable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
APPL_INFO("==================================");
|
APPL_INFO("==================================");
|
||||||
APPL_INFO("== ZEUS gateway start ==");
|
APPL_INFO("== ZEUS gateway start ==");
|
||||||
APPL_INFO("==================================");
|
APPL_INFO("==================================");
|
||||||
@ -219,10 +250,29 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
} else {
|
} else {
|
||||||
bool routerAlive = true;
|
bool routerAlive = true;
|
||||||
std::vector<ememory::SharedPtr<PlugginAccess>> listElements;
|
std::vector<ememory::SharedPtr<PlugginAccess>> listElements;
|
||||||
for (auto &it: services) {
|
if ( services.size() == 1
|
||||||
ememory::SharedPtr<PlugginAccess> tmp = ememory::makeShared<PlugginAccess>(it);
|
&& services[0] == "all") {
|
||||||
|
for (auto &it: listAvaillableServices) {
|
||||||
|
ememory::SharedPtr<PlugginAccess> tmp = ememory::makeShared<PlugginAccess>(it.first, it.second);
|
||||||
listElements.push_back(tmp);
|
listElements.push_back(tmp);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for (auto &it: services) {
|
||||||
|
// find the real service name:
|
||||||
|
bool find = false;
|
||||||
|
for (auto &it2: listAvaillableServices) {
|
||||||
|
if (it2.first == it) {
|
||||||
|
ememory::SharedPtr<PlugginAccess> tmp = ememory::makeShared<PlugginAccess>(it2.first, it2.second);
|
||||||
|
listElements.push_back(tmp);
|
||||||
|
find = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (find == false) {
|
||||||
|
APPL_ERROR("Can not find the service: " << it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for (auto &it: listElements) {
|
for (auto &it: listElements) {
|
||||||
it->init(_argc, _argv, basePath);
|
it->init(_argc, _argv, basePath);
|
||||||
}
|
}
|
||||||
|
@ -239,9 +239,7 @@ ememory::SharedPtr<appl::GateWayInterface> appl::Router::get(const std::string&
|
|||||||
int ret = execlp( binary.c_str(),
|
int ret = execlp( binary.c_str(),
|
||||||
binary.c_str(), // must repeate the binary name to have the name as first argument ...
|
binary.c_str(), // must repeate the binary name to have the name as first argument ...
|
||||||
userConf.c_str(),
|
userConf.c_str(),
|
||||||
"--srv=user",
|
"--srv=all",
|
||||||
"--srv=picture",
|
|
||||||
"--srv=video",
|
|
||||||
delay.c_str(),
|
delay.c_str(),
|
||||||
basePath.c_str(),
|
basePath.c_str(),
|
||||||
logFile.c_str(),
|
logFile.c_str(),
|
||||||
|
@ -187,6 +187,33 @@ zeus::ObjectRemote zeus::Client::getService(const std::string& _name) {
|
|||||||
return zeus::ObjectRemote(ret.get());
|
return zeus::ObjectRemote(ret.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
zeus::Future<int32_t> zeus::Client::getServiceCount() {
|
||||||
|
return call(ZEUS_NO_ID_OBJECT, ZEUS_ID_GATEWAY, "getServiceCount");
|
||||||
|
}
|
||||||
|
|
||||||
|
zeus::Future<std::vector<std::string>> zeus::Client::getServiceList() {
|
||||||
|
return call(ZEUS_NO_ID_OBJECT, ZEUS_ID_GATEWAY, "getServiceList");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO : This is an active waiting ==> this is bad ... ==> use future, it will be better
|
||||||
|
bool zeus::Client::waitForService(const std::string& _serviceName) {
|
||||||
|
int32_t delayMax = 10;
|
||||||
|
while (delayMax > 0) {
|
||||||
|
auto listValues = getServiceList();
|
||||||
|
listValues.wait();
|
||||||
|
for (auto &it: listValues.get()) {
|
||||||
|
if (it == _serviceName) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
delayMax--;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void zeus::Client::onPropertyChangeIp() {
|
void zeus::Client::onPropertyChangeIp() {
|
||||||
disconnect();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
@ -156,6 +156,11 @@ namespace zeus {
|
|||||||
* @brief Display all connected object remote and local ...
|
* @brief Display all connected object remote and local ...
|
||||||
*/
|
*/
|
||||||
void cleanDeadObject();
|
void cleanDeadObject();
|
||||||
|
public:
|
||||||
|
zeus::Future<int32_t> getServiceCount();
|
||||||
|
zeus::Future<std::vector<std::string>> getServiceList();
|
||||||
|
// TODO : This is an active waiting ==> this is bad ... ==> use future, it will be better
|
||||||
|
bool waitForService(const std::string& _serviceName);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,12 +276,18 @@ int32_t zeus::WebServer::writeBinary(ememory::SharedPtr<zeus::Message> _obj) {
|
|||||||
|
|
||||||
bool zeus::WebServer::onReceiveUri(const std::string& _uri, const std::vector<std::string>& _protocols) {
|
bool zeus::WebServer::onReceiveUri(const std::string& _uri, const std::vector<std::string>& _protocols) {
|
||||||
ZEUS_INFO("Receive Header uri: " << _uri);
|
ZEUS_INFO("Receive Header uri: " << _uri);
|
||||||
|
bool findProtocol = false;
|
||||||
for (auto &it : _protocols) {
|
for (auto &it : _protocols) {
|
||||||
if (it == "zeus/1.0") {
|
if (it == "zeus/1.0") {
|
||||||
m_connection.setProtocol(it);
|
m_connection.setProtocol(it);
|
||||||
|
findProtocol = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (findProtocol == false) {
|
||||||
|
ZEUS_ERROR("Disable connection request URI='" << _uri << "' with wrong protocol:" << _protocols);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// TODO : Add better return on specific user ...
|
// TODO : Add better return on specific user ...
|
||||||
if (m_observerRequestUri != nullptr) {
|
if (m_observerRequestUri != nullptr) {
|
||||||
return m_observerRequestUri(_uri);
|
return m_observerRequestUri(_uri);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user