Add the check for the existense of the client

Don't add the client if it is already configured.

Change-Id: Ib0c64e2eb73b272a290599e1b83630a8ab5709ec
Signed-off-by: Ratan Gupta <ratagupt@linux.vnet.ibm.com>
diff --git a/snmp_conf_manager.cpp b/snmp_conf_manager.cpp
index b523c5d..52f4678 100644
--- a/snmp_conf_manager.cpp
+++ b/snmp_conf_manager.cpp
@@ -31,7 +31,8 @@
 
 std::string ConfManager::client(std::string address, uint16_t port)
 {
-    // TODO: Check whether the given manager is already there or not.
+    // will throw exception if it is already configured.
+    checkClientConfigured(address, port);
 
     lastClientId++;
     try
@@ -62,6 +63,31 @@
     return objPath.string();
 }
 
+void ConfManager::checkClientConfigured(const std::string& address,
+                                        uint16_t port)
+{
+    if (address.empty())
+    {
+        log<level::ERR>("Invalid address");
+        elog<InvalidArgument>(Argument::ARGUMENT_NAME("ADDRESS"),
+                              Argument::ARGUMENT_VALUE(address.c_str()));
+    }
+
+    for (const auto& val : clients)
+    {
+        if (val.second.get()->address() == address &&
+            val.second.get()->port() == port)
+        {
+            log<level::ERR>("Client already exist");
+            // TODO Add the error(Object already exist) in the D-Bus interface
+            // then make the change here,meanwhile send the Internal Failure.
+            elog<InvalidArgument>(
+                Argument::ARGUMENT_NAME("ADDRESS"),
+                Argument::ARGUMENT_VALUE("Client already exist."));
+        }
+    }
+}
+
 void ConfManager::deleteSNMPClient(Id id)
 {
     auto it = clients.find(id);