GetCurrentDevice will list devices managed

Change-Id: I83202aa5b4f9af8e4b1e662b589ce8d795808a8d
diff --git a/demo_test/cmd_client/Note b/demo_test/cmd_client/Note
index ca0c094..4781181 100644
--- a/demo_test/cmd_client/Note
+++ b/demo_test/cmd_client/Note
@@ -47,11 +47,14 @@
 Set IP 192.168.4.27 port 8888 vendor "edgecore" freq 180
 									attach:192.168.4.27:8888:edgecore:180
 --------------------------------------------------------------------------------------
-set multi-deivies info                                                  Example:
+set multi-device info                                                  Example:
 
 									attach:192.168.4.27:8888:edgecore:180
 									attach:192.168.3.34:8888:edgecore:180
 --------------------------------------------------------------------------------------
+Get Current List of Devices monitored					showdevices
+									Return from server: 192.168.4.26:8888,192.168.4.27:8888
+--------------------------------------------------------------------------------------
 UnSubscribe all events(ResourceAdded/ResourceRemoved/Alert)		unsub:192.168.4.27:8888:add:rm:alert
 --------------------------------------------------------------------------------------
 Subscribe all events(ResourceAdded/ResourceRemoved/Alert) 		sub:192.168.4.27:8888:add:rm:alert
diff --git a/demo_test/test.go b/demo_test/test.go
index 05582ad..d1d7ca9 100644
--- a/demo_test/test.go
+++ b/demo_test/test.go
@@ -128,8 +128,11 @@
 	vendorinfo.Vendor = vendor
 	var ret_msg *importer.EventList
 	ret_msg, err := cc.GetEventList(ctx, vendorinfo)
-
-	return err, ret_msg.Events
+	if err != nil {
+		return err, nil
+	} else {
+		return err, ret_msg.Events
+	}
 }
 
 /*///////////////////////////////////////////////////////////////////////*/
@@ -143,8 +146,11 @@
 	currentdeviceinfo.IpAddress = ip_address
 	var ret_msg *importer.EventList
 	ret_msg, err := cc.GetCurrentEventList(ctx, currentdeviceinfo)
-
-	return err, ret_msg.Events
+	if err != nil {
+		return err, nil
+	} else {
+		return err, ret_msg.Events
+	}
 }
 
 /*///////////////////////////////////////////////////////////////////////*/
@@ -161,6 +167,23 @@
 	return err
 }
 
+/*///////////////////////////////////////////////////////////////////////*/
+// Allows user to get the current devices that are monitored
+//
+//
+/*///////////////////////////////////////////////////////////////////////*/
+func GetCurrentDevices() (error, []string) {
+	fmt.Println("Testing GetCurrentDevices\n")
+	empty := new(importer.Empty)
+	var ret_msg *importer.DeviceList
+	ret_msg, err := cc.GetCurrentDevices(ctx, empty)
+	if err != nil {
+		return err, nil
+	} else {
+		return err, ret_msg.Ip
+	}
+}
+
 func init() {
 	Formatter := new(log.TextFormatter)
 	Formatter.TimestampFormat = "02-01-2006 15:04:05"
@@ -439,6 +462,26 @@
 					}
 				}
 
+			case "showdevices":
+				cmd_size := len(s)
+				fmt.Print("cmd is :", cmd, cmd_size)
+				if cmd_size > 2 || cmd_size < 0 {
+					fmt.Print("error event !!")
+					newmessage = "error event !!"
+				} else {
+					err, currentlist := GetCurrentDevices()
+
+					if err != nil {
+						errStatus, _ := status.FromError(err)
+						fmt.Println(errStatus.Message())
+						fmt.Println(errStatus.Code())
+						newmessage = errStatus.Message()
+						fmt.Print("showdevices error!!")
+					} else {
+						fmt.Print("showdevices ", currentlist)
+						newmessage = strings.Join(currentlist[:], ", ")
+					}
+				}
 			case "QUIT":
 				loop = false
 				newmessage = "QUIT"
diff --git a/main.go b/main.go
index bc0e3ba..0510876 100644
--- a/main.go
+++ b/main.go
@@ -75,7 +75,7 @@
 }
 
 func (s *Server) ClearCurrentEventList(c context.Context, info *importer.Device) (*empty.Empty, error) {
-	fmt.Println("Received GetCurrentEventList\n")
+	fmt.Println("Received ClearCurrentEventList\n")
 	ip_address := info.IpAddress
 	_, found := s.devicemap[ip_address]
 	if !found {
@@ -97,7 +97,7 @@
 }
 
 func (s *Server) GetCurrentEventList(c context.Context, info *importer.Device) (*importer.EventList, error) {
-	fmt.Println("Received ClearCurrentEventList\n")
+	fmt.Println("Received GetCurrentEventList\n")
 	_, found := s.devicemap[info.IpAddress]
 	if !found {
 		return nil, status.Errorf(codes.NotFound, "Device not registered")
@@ -277,6 +277,22 @@
 	return &empty.Empty{}, nil
 }
 
+func (s *Server) GetCurrentDevices(c context.Context, e *importer.Empty) (*importer.DeviceList, error) {
+	fmt.Println("In Received GetCurrentDevices\n")
+
+	if len(s.devicemap) == 0 {
+		return nil, status.Errorf(codes.NotFound, "Devices not registered")
+	}
+	dl := new(importer.DeviceList)
+	for k, v := range s.devicemap {
+		if v != nil {
+			fmt.Printf("IpAdd[%s] \n", k)
+			dl.Ip = append(dl.Ip, k)
+		}
+	}
+	return dl, nil
+}
+
 func NewGrpcServer(grpcport string) (l net.Listener, g *grpc.Server, e error) {
 	fmt.Printf("Listening %s\n", grpcport)
 	g = grpc.NewServer()
diff --git a/proto/importer.proto b/proto/importer.proto
index dd85cd1..e7117b1 100644
--- a/proto/importer.proto
+++ b/proto/importer.proto
@@ -36,8 +36,12 @@
 	string IpAddress = 1;
 }
 
+message DeviceList {
+        repeated string ip = 1;
+}
 
 message Empty {}
+
 service device_management {
     rpc SendDeviceInfo(DeviceInfo) returns (google.protobuf.Empty) {}
 
@@ -53,6 +57,7 @@
 
     rpc ClearCurrentEventList(Device) returns (google.protobuf.Empty) {}
 
+	rpc GetCurrentDevices(Empty) returns (DeviceList) {}
 }