Commit 668fa1c2 authored by rygelgit's avatar rygelgit

This commit includes handling embedded device listing.

- All embedded devices are listed in the device list when selecting for DIAGE testing.
- DIAGC.pl also includes changes to display already devices in that session.
parent d053fff7
......@@ -42,18 +42,19 @@ use responsevalidator::ResponseValidator;
START:
our ($TEST_OPTION, $HOSTIP, $HOSTPORT, $CONTROL_URL) = '';
our ($diage_devices, $device_name, $diage_ip, $diage_port, $control_url);
print "\33[1;33m------- Choose an option -------\33[m\n";
print "1. Search DIAGE capable devices \n";
print "2. Manual DIAGE device testing \n";
print "3. Exit Application \n";
print "3. List Searched devices \n";
print "4. Exit Application \n";
print "\33[1;33mEnter the option number : \33[m";
our $SEARCH_OPTS = <>;
chomp $SEARCH_OPTS;
switch($SEARCH_OPTS){
case 1 {
my ($diage_devices, $diage_ip, $diage_port, $control_url) = SearchDevices::lookup_diage_device;
($diage_devices, $device_name, $diage_ip, $diage_port, $control_url) = SearchDevices::lookup_diage_device;
print "\33[1;33mChoose the corresponding device number to start testing: \33[m\n";
my $device_count=0;
......@@ -62,7 +63,7 @@ switch($SEARCH_OPTS){
foreach my $device_temp (@$diage_devices) {
print "----------------------------------------\33[m\n";
print "\33[1;33m[" . ($device_count + 1) . "] : " . $device_temp->getfriendlyname() . "\33[m\n";
print "\33[1;33m[" . ($device_count + 1) . "] : " . @$device_name[$device_count] . "\33[m\n";
print "\33[1;33mDevice IP : " . @$diage_ip[$device_count] . "\33[m\n";
print "\33[1;33mDevice Port : " . @$diage_port[$device_count] . "\33[m\n";
print "\33[1;33mControl URL : " . @$control_url[$device_count] . "\33[m\n";
......@@ -83,8 +84,35 @@ switch($SEARCH_OPTS){
}
case 2 {
Util::print_diagc_start;
}
case 3 {
}
case 3 {
print "\33[1;33mChoose the corresponding device number to start testing: \33[m\n";
my $device_count=0;
print "****************************************\n";
print "****************************************\n";
foreach my $device_temp (@$diage_devices) {
print "----------------------------------------\33[m\n";
print "\33[1;33m[" . ($device_count + 1) . "] : " . $device_temp->getfriendlyname() . "\33[m\n";
print "\33[1;33mDevice IP : " . @$diage_ip[$device_count] . "\33[m\n";
print "\33[1;33mDevice Port : " . @$diage_port[$device_count] . "\33[m\n";
print "\33[1;33mControl URL : " . @$control_url[$device_count] . "\33[m\n";
$device_count++;
}
print "****************************************\n";
print "****************************************\n";
print "\33[1;33mChoose the device number: \33[m";
my $DEVICE_NO = <>;
chomp $DEVICE_NO;
$HOSTIP = @$diage_ip[$DEVICE_NO - 1];
$HOSTPORT = @$diage_port[$DEVICE_NO - 1];
$CONTROL_URL = @$control_url[$DEVICE_NO - 1];
Util::print_diagc_start;
}
case 4 {
exit;
}
else { exit;}
......
......@@ -29,6 +29,7 @@
#
package SearchDevices;
use utils::UPnPWrapper;
use Net::UPnP::Device;
use Net::UPnP::ControlPoint;
......@@ -43,37 +44,58 @@ sub search_devices {
sub lookup_diage_device {
my ($device_list_search, $device_ip_list, $device_port_list) = search_devices;
$devNum= 0;
my (@temp_device_list, @temp_device_ip, @temp_device_port, @temp_scpd_url)= ();
my (@temp_device_list, @temp_device_name, @temp_device_ip, @temp_device_port, @temp_scpd_url)= ();
foreach my $dev_temp (@$device_list_search) {
my @service_list = $dev_temp->getservicelist();
my $diage_present='false';
foreach $service_temp (@service_list) {
if ($service_temp->getserviceid() eq 'urn:upnp-org:serviceId:BasicManagement') {
$diage_present='true';
}
}
my @service_list = $dev_temp->getservicelist();
my $diage_present='false';
foreach $service_temp (@service_list) {
if ($service_temp->getserviceid() eq 'urn:upnp-org:serviceId:BasicManagement') {
$diage_present='true';
}
}
if ($diage_present eq 'false') {
$devNum++;
next;
}
my $parser = XML::LibXML->new;
$doc = $parser->parse_string($dev_temp->getdescription());
my @nodes = $doc->getElementsByTagName("service");
foreach my $node (@nodes) {
if ($node->hasChildNodes()){
my $service_no_version=$node->getChildrenByTagName( "serviceType" );
if ((substr $service_no_version, 0 , length($service_no_version)-1) eq 'urn:schemas-upnp-org:service:BasicManagement:') {
push (@temp_scpd_url, $node->getChildrenByTagName("controlURL")->string_value());
}
}
}
my $parser = XML::LibXML->new;
my $doc = $parser->parse_string($dev_temp->getdescription());
my $root = $doc->documentElement();
my @embedded_devices = $root->getElementsByTagName("device");
my $device_num =0;
foreach my $temp_embedded_devices (@embedded_devices) {
my @service_list=$temp_embedded_devices->getChildrenByTagName('serviceList');
foreach my $temp_service_list (@service_list) {
my @services = $temp_service_list->getChildrenByTagName("service");
foreach my $temp_services (@services) {
if ($temp_services->hasChildNodes()){
my $service_no_version=$temp_services->getChildrenByTagName( "serviceType" );
if ((substr $service_no_version, 0 , length($service_no_version)-1) eq 'urn:schemas-upnp-org:service:BasicManagement:') {
if ($device_num > 0) {
# Create new Embedded devices
my $dev = Net::UPnP::Device->new();
# TODO: Add only the embedded device description
$dev->setdescription($dev_temp->getdescription());
push (@temp_device_list , $dev);
push (@temp_device_name, 'Embedded');
} else {
# Add the root device
push (@temp_device_list , $dev_temp);
push (@temp_device_name, $dev_temp->getfriendlyname());
}
push (@temp_device_ip, @$device_ip_list[$devNum]);
push (@temp_device_port, @$device_port_list[$devNum]);
push (@temp_scpd_url, $temp_services->getChildrenByTagName("controlURL")->string_value());
}
}
}
}
$device_num++;
}
push (@temp_device_list , $dev_temp);
push (@temp_device_ip, @$device_ip_list[$devNum]);
push (@temp_device_port, @$device_port_list[$devNum]);
#print "[" . ($devNum + 1) . "] : " . $dev_temp->getfriendlyname() . "\n";
#print "Device IP : " . @$device_ip_list[$devNum] . "\n";
#print "Device Port : " . @$device_port_list[$devNum] . "\n";
......@@ -81,7 +103,7 @@ sub lookup_diage_device {
}
print "\33[1;36mDevices with DIAGE capability: " . @temp_device_list . "\33[m\n";
#print "DIAGC Control URL: " . "@temp_scpd_url" . "\n";
return (\@temp_device_list, \@temp_device_ip, \@temp_device_port, \@temp_scpd_url);
return (\@temp_device_list, \@temp_device_name, \@temp_device_ip, \@temp_device_port, \@temp_scpd_url);
}
1;
......@@ -61,7 +61,7 @@ while( select($reader_output = $reader_input, undef, undef, 10) ) {
my $get_response = $user_agent->request($get_request);
my $get_content = $get_response->content;
print $get_content;
# print $get_content;
# Keeping this in here for now. But the performance using HTTP:Request is slow.
#my $http_request = Net::UPnP::HTTP->new();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment