Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed segmentation faults, corrected commands and output need to fix o... #513

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ string CPU::getPropertyValue(string * property, string * component)

string CPU::model(string model)
{
return Utils::exec(string("echo -n `uname -p`"));
//return Utils::exec(string("echo -n `uname -p`"));
return Utils::exec(string("cat /proc/cpuinfo | grep -m 1 'model name'")); //CPU model name
}

string CPU::currentLoad(string currentload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ string Device::getPropertyValue(string * property, string * component)

string Device::imei(string deviceName)
{
return "imei";
return "Can't Retrieve from OS";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, the API should respond false if the property is not supported. I have opened the jira issue http://jira.webinos.org/browse/WP-916

}

string Device::model(string deviceName)
{
return "model";
return "Can't Retrieve from OS";
}

string Device::vendor(string deviceName)
{
return "vendor";
return "Can't Retrieve from OS";
}

string Device::version(string deviceName)
{
return "version";
return "Can't Retrieve from OS";
}

Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ string InputDevice::getPropertyValue(string * property, string * component)

string InputDevice::type(string inputDeviceName)
{
string res;
string res1, res2, result;

res = Utils::exec(string("lsusb"));
return string(res);
//Giving Info for USB and PCI both
res1 = Utils::exec(string("lsusb"));
res2 = Utils::exec(string("lspci"));
result = res1 + res2;
return string(result);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,16 @@ return string(res);

string MemoryUnit::volatil(string memoUnit)
{
string line, res, result;
string res1, res2, res3, result;
size_t pos;

ifstream finfo("/proc/version"); //uname -r // ("/proc/version")
while(getline(finfo,line)) {
stringstream str(line);

if ( getline(str, line)){
pos = line.find("Ubuntu"); // position of "live" in str
result = line.substr (pos);
res = result.substr (0,27);
break;
}
}
return string(res);
res1 = Utils::exec(string("cat /proc/meminfo | grep MemTotal"));
res2 = Utils::exec(string("cat /proc/meminfo | grep MemFree"));
res3 = Utils::exec(string("cat /proc/meminfo | grep Buffers"));

result = res1 + res2 + res3;

return string(result);
}


Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,75 @@ string OperatingSystem::language(string oslanguage)

string OperatingSystem::version(string osversion)
{
return Utils::exec(string("echo -n `uname -sr`"));
//return Utils::exec(string("echo -n `uname -sr`"));
string line, result, res;
size_t pos, pos_endl;

line = Utils::exec(string("lsb_release -a"));
pos = line.find("Release");
if (pos < line.size())
{
result = line.substr (pos);
res = result.substr (8,6);
return string(res);
}
else
{
return "No Release Data";
}
/* pos = line.find("Release") + 10;
pos_endl = line.find('\n', pos);

return line.substr (pos, pos_endl - pos - 1);*/
}

string OperatingSystem::name(string osname)
{
return Utils::exec(string("echo -n `cat /etc/*version /etc/*release 2>/dev/null`"));
string line, result, res;
size_t pos, pos_endl;

line = Utils::exec(string("lsb_release -a"));
pos = line.find("Description");
if (pos < line.size())
{
result = line.substr (pos);
res = result.substr (12,13);
return string(res);
}
else
{
return "No OS Name Data";
}

/*line = Utils::exec(string("lsb_release -a"));
pos = line.find("Description") + 10;
pos_endl = line.find('\n', pos);

return line.substr (pos, pos_endl - pos - 1);*/
//return Utils::exec(string("echo -n `cat /etc/*version /etc/*release 2>/dev/null`"));
}

string OperatingSystem::vendor(string osvendor)
{
return Utils::exec(string("echo -n `uname -o`"));
string line, result, res;
size_t pos, pos_endl;

line = Utils::exec(string("lsb_release -a"));
pos = line.find("Distributor ID");
if (pos < line.size())
{
result = line.substr (pos);
res = result.substr (15,8);
return string(res);
}
else
{
return "No Vendor Data";
}
/* line = Utils::exec(string("lsb_release -a"));
pos = line.find("Distributor ID") + 10;
pos_endl = line.find('\n', pos);

return line.substr (pos, pos_endl - pos - 1);*/
// return Utils::exec(string("echo -n `uname -o`"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,25 @@ string WiFiHardware::getPropertyValue(string * property, string * component)

string WiFiHardware::status(string wifiHardwareName)
{
string line;
size_t pos, pos_endl;

line = Utils::exec(string("iwconfig"));
pos = line.find("Access Point") + 14;
pos_endl = line.find(' ', pos);

return "Associated to: " + line.substr (pos, pos_endl - pos);
string line, res, result;
size_t pos;

line = Utils::exec(string("iwconfig 2>&1")); //cat proc/load
pos = line.find("ESSID");
//cout<<line.size()<<endl;
//cout<<pos<<endl;
if(pos < line.size())
{
//cout<<"check"<<endl;
result = line.substr(pos);
//cout<<result<<endl;
res = result.substr(6,10);
return string(res);
}
else
{
return "No ssid found";
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,55 +47,65 @@ string WiFiNetwork::getPropertyValue(string * property, string * component)

}

string WiFiNetwork::ssid(string wifiNetworkName)
string WiFiNetwork::ssid(string wifiNetworkssid)
{
string line, res, result;
size_t pos;

line = Utils::exec(string("iwconfig")); //cat proc/loadavg
line = Utils::exec(string("iwconfig 2>&1")); //cat proc/load
pos = line.find("ESSID");
result = line.substr (pos);
res = result.substr (6,10);
if (res == "ESSID")
{
if(pos < line.size())
{
result = line.substr(pos);
res = result.substr(6,10);
return string(res);
}
else
}
else
{
return "No ssid found";
}
//return "true";
}

string WiFiNetwork::signalStrength(string wifiNetworkName)
string WiFiNetwork::signalStrength(string wifiNetworksignal)
{
string line, res, result;
size_t pos;

line = Utils::exec(string("iwconfig")); //cat proc/loadavg
line = Utils::exec(string("iwconfig 2>&1")); //cat proc/loadavg
pos = line.find("Tx-Power");
if (pos < line.size())
{
result = line.substr (pos);
res = result.substr (9,8);

return string(res);
}
else
{
return "No Signal Data";
}
//return "true";
}

string WiFiNetwork::networkStatus(string wifiNetworkName)
string WiFiNetwork::networkStatus(string wifiNetworkStatus)
{
return "networkStatus not Implemented";
return "Network Status not Implemented";
}

string WiFiNetwork::ipAddress(string wifiNetworkName)
string WiFiNetwork::ipAddress(string wifiNetworkip)
{
string line, res, result;
size_t pos;

line = Utils::exec(string("ifconfig -a")); // iwconfig
pos = line.find("inet addr");
result = line.substr (pos);
res = result.substr (10,27);
res = result.substr (10,15);

return string(res);
}

string WiFiNetwork::macAddress(string wifiNetworkName)
string WiFiNetwork::macAddress(string wifiNetworkmac)
{

string line, res, result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,18 @@ string WiredNetwork::networkStatus(string wiredNetworkName)
string line, res, result;
size_t pos;

line = Utils::exec(string("ifconfig -a")); //netstat
pos = line.find("inet addr");
result = line.substr (pos);
res = result.substr (10,27);

return string(res);

line = Utils::exec(string("iwconfig 2>&1")); //cat proc/load
pos = line.find("ESSID");
if(pos < line.size())
{
result = line.substr(pos);
res = result.substr(6,10);
return string(res);
}
else
{
return "No ssid found";
}
// return "networkStatus";
}

Expand All @@ -66,7 +71,7 @@ size_t pos;
line = Utils::exec(string("ifconfig -a"));
pos = line.find("inet addr");
result = line.substr (pos);
res = result.substr (10,27);
res = result.substr (10,15);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are you so sure that the pos is positive (not -1 to indicate that this was not found), and that the result is at least 25 characters long. This will definitely through exceptions if no network info is available...
Moreover, there is a dedicated library for network info as described in http://stackoverflow.com/questions/212528/get-the-ip-address-of-the-machine.


return string(res);
}
Expand Down