From 30f6b057231fd08141e6f8514b140a9bba48727e Mon Sep 17 00:00:00 2001
From: amichelo <andrea.michelotti@lnf.infn.it>
Date: Wed, 3 Nov 2021 23:40:13 +0100
Subject: [PATCH] controller update no directio

---
 ChaosMetadataService/api/ApiManagement.cpp | 77 ++++++++++++++++++++
 ChaosMetadataService/api/ApiManagement.h   | 85 ++++++++++++++++++++++
 chaos/common/message/MDSMessageChannel.cpp |  2 +-
 chaos/common/message/MDSMessageChannel.h   |  2 +-
 chaos_service_common/ChaosManager.cpp      |  2 +-
 chaos_service_common/ChaosManager.h        |  2 +-
 6 files changed, 166 insertions(+), 4 deletions(-)
 create mode 100644 ChaosMetadataService/api/ApiManagement.cpp
 create mode 100644 ChaosMetadataService/api/ApiManagement.h

diff --git a/ChaosMetadataService/api/ApiManagement.cpp b/ChaosMetadataService/api/ApiManagement.cpp
new file mode 100644
index 000000000..bd52c80e5
--- /dev/null
+++ b/ChaosMetadataService/api/ApiManagement.cpp
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2012, 2017 INFN
+ *
+ * Licensed under the EUPL, Version 1.2 or – as soon they
+ * will be approved by the European Commission - subsequent
+ * versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the
+ * Licence.
+ * You may obtain a copy of the Licence at:
+ *
+ * https://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in
+ * writing, software distributed under the Licence is
+ * distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the Licence for the specific language governing
+ * permissions and limitations under the Licence.
+ */
+
+#include "ApiManagement.h"
+
+#include <chaos/common/utility/ObjectFactoryRegister.h>
+
+#include <boost/foreach.hpp>
+
+using namespace chaos::common::utility;
+using namespace chaos::metadata_service;
+using namespace chaos::metadata_service::api;
+using namespace chaos::common::network;
+//! default consturctor
+ApiManagement::ApiManagement(){}
+
+//! default destructor
+ApiManagement::~ApiManagement() {
+	clearGroupList();
+}
+
+void ApiManagement::init(void* init_data)  {
+    
+	//register all available api group
+	std::vector<std::string> all_registered_groups;
+	ObjectFactoryRegister<AbstractApiGroup>::getInstance()->getAllRegisteredName(all_registered_groups);
+	BOOST_FOREACH( std::string name, all_registered_groups ) {
+        //get the api group instance
+		AbstractApiGroup * instance = ObjectFactoryRegister<AbstractApiGroup>::getInstance()->getNewInstanceByName(name);
+        
+        //initialize the api group
+        InizializableService::initImplementation(instance,
+                                                 NULL,
+                                                 instance->getName(),
+                                                 __PRETTY_FUNCTION__);
+        //register the api group
+		addApiAgroup(instance);
+	}
+}
+void ApiManagement::deinit()  {
+	clearGroupList();
+}
+
+void ApiManagement::clearGroupList() {
+	for(ApiGroupListIterator it = installed_api_group_list.begin();
+		it != installed_api_group_list.end();
+		it++) {
+        //get api group reference
+        ApiGroupListElement group = *it;
+        
+        //deregister the action
+        NetworkBroker::getInstance()->deregisterAction((*it).get());
+        
+        //initialize the api group
+        InizializableService::deinitImplementation(group.get(),
+                                                   group->getName(),
+                                                   __PRETTY_FUNCTION__);
+	}
+}
diff --git a/ChaosMetadataService/api/ApiManagement.h b/ChaosMetadataService/api/ApiManagement.h
new file mode 100644
index 000000000..d1c3e5de1
--- /dev/null
+++ b/ChaosMetadataService/api/ApiManagement.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2012, 2017 INFN
+ *
+ * Licensed under the EUPL, Version 1.2 or – as soon they
+ * will be approved by the European Commission - subsequent
+ * versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the
+ * Licence.
+ * You may obtain a copy of the Licence at:
+ *
+ * https://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in
+ * writing, software distributed under the Licence is
+ * distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the Licence for the specific language governing
+ * permissions and limitations under the Licence.
+ */
+#ifndef __CHAOSFramework__ApiManagement__
+#define __CHAOSFramework__ApiManagement__
+
+#include "AbstractApiGroup.h"
+#include "../mds_types.h"
+#include "../batch/mds_service_batch.h"
+
+#include <chaos/common/utility/InizializableService.h>
+#include <chaos/common/network/NetworkBroker.h>
+#include <vector>
+#include <boost/shared_ptr.hpp>
+
+namespace chaos {
+	namespace metadata_service {
+		namespace api {
+			//!typedef for the group list
+            typedef ChaosSharedPtr<AbstractApiGroup>          ApiGroupListElement;
+			typedef std::vector< ApiGroupListElement >           ApiGroupList;
+			typedef std::vector< ApiGroupListElement >::iterator ApiGroupListIterator;
+			
+			class ApiManagement:
+			public chaos::common::utility::InizializableService {
+                
+				//! api group list
+				ApiGroupList installed_api_group_list;
+				
+				void clearGroupList();
+			public:
+				//! default consturctor
+				ApiManagement();
+				
+				//! default destructor
+				~ApiManagement();
+				
+				//! install an instance of an api group
+				void addApiAgroup(AbstractApiGroup *instance) {
+                    chaos::common::network::NetworkBroker::getInstance()->registerAction(instance);
+					//we have an instance so we can register that action
+					installed_api_group_list.push_back(ChaosSharedPtr<AbstractApiGroup>(instance));
+				}
+				
+				//! install a class as api group
+				template<typename T>
+				void addApiAgroup() {
+					//allcoate the instsancer for the AbstractApi depending by the template
+					ChaosUniquePtr<INSTANCER(T, AbstractApiGroup)> i(ALLOCATE_INSTANCER(T, AbstractApiGroup));
+					
+					//get api instance
+					T *instance = (T*)i->getInstance();
+					if(instance) {
+						chaos::common::network::NetworkBroker::getInstance()->registerAction(instance);
+						//we have an instance so we can register that action
+						installed_api_group_list.push_back(ChaosSharedPtr<AbstractApiGroup>(instance));
+					}
+				}
+				
+				void init(void* init_data);
+				void deinit();
+			};
+			
+		}
+	}
+}
+
+#endif /* defined(__CHAOSFramework__ApiManagement__) */
diff --git a/chaos/common/message/MDSMessageChannel.cpp b/chaos/common/message/MDSMessageChannel.cpp
index 16d6d437b..95b05c843 100644
--- a/chaos/common/message/MDSMessageChannel.cpp
+++ b/chaos/common/message/MDSMessageChannel.cpp
@@ -898,7 +898,7 @@ int MDSMessageChannel::queryDataCloud(const std::string& key,
                                        const uint64_t end_ts,
                                        const uint32_t page_dimension,
                                        chaos::common::direct_io::channel::opcode_headers::SearchSequence& last_sequence,
-                                       chaos::common::direct_io::channel::opcode_headers::QueryResultPage& found_element_page,
+                                       chaos::common::data::VectorCDWShrdPtr& found_element_page,
                                        bool only_index,int32_t millisec_to_wait){
                                            int err = ErrorCode::EC_NO_ERROR;
     ChaosUniquePtr<chaos::common::data::CDataWrapper> message(new CDataWrapper());
diff --git a/chaos/common/message/MDSMessageChannel.h b/chaos/common/message/MDSMessageChannel.h
index 0b9121599..12f2491bb 100644
--- a/chaos/common/message/MDSMessageChannel.h
+++ b/chaos/common/message/MDSMessageChannel.h
@@ -366,7 +366,7 @@ namespace chaos {
                                        const uint64_t end_ts,
                                        const uint32_t page_dimension,
                                        chaos::common::direct_io::channel::opcode_headers::SearchSequence& last_sequence,
-                                       chaos::common::direct_io::channel::opcode_headers::QueryResultPage& found_element_page,
+                                       chaos::common::data::VectorCDWShrdPtr& found_element_page,
                                        bool only_index = false,int32_t millisec_to_wait=10000);
                     //! Perform a  data delete operation on a key
                     /*!
diff --git a/chaos_service_common/ChaosManager.cpp b/chaos_service_common/ChaosManager.cpp
index d968afb41..03f12260f 100644
--- a/chaos_service_common/ChaosManager.cpp
+++ b/chaos_service_common/ChaosManager.cpp
@@ -287,7 +287,7 @@ int ChaosManager::queryDataCloud(const std::string& key,
                                        const uint64_t end_ts,
                                        const uint32_t page_dimension,
                                        chaos::common::direct_io::channel::opcode_headers::SearchSequence& last_sequence,
-                                       chaos::common::direct_io::channel::opcode_headers::QueryResultPage& found_element_page,
+                                       chaos::common::data::VectorCDWShrdPtr& found_element_page,
                                        int32_t millisec_to_wait){
   if(storage_driver){
     chaos::metadata_service::api::service::QueryDataCloud node;
diff --git a/chaos_service_common/ChaosManager.h b/chaos_service_common/ChaosManager.h
index 7f276f07f..ba7e80f06 100644
--- a/chaos_service_common/ChaosManager.h
+++ b/chaos_service_common/ChaosManager.h
@@ -136,7 +136,7 @@ int queryDataCloud(const std::string& key,
                                        const uint64_t end_ts,
                                        const uint32_t page_dimension,
                                        chaos::common::direct_io::channel::opcode_headers::SearchSequence& last_sequence,
-                                       chaos::common::direct_io::channel::opcode_headers::QueryResultPage& found_element_page,
+                                       chaos::common::data::VectorCDWShrdPtr& found_element_page,
                                        int32_t millisec_to_wait=10000);
 int deleteDataCloud(const std::string& key,
                                        const uint64_t start_ts,
-- 
GitLab