Skip to content

Commit

Permalink
Changed the function names
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaganathan, Bantheswaran committed Jan 25, 2018
1 parent 22ce186 commit 0a2f866
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 40 deletions.
12 changes: 6 additions & 6 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ When the addon is ready, `callback` would be called with `true` which indicates
#### spyOff()
`spyOff` should be called when you wanted to stop listening for the usb device change.

#### getAvailableUSBDevices()
`getAvailableUSBDevices` would written list of `Device` objects if available otherwise empty list would be returned. This method does not take any arguments.
#### getAvailableUSBStorageDevices()
`getAvailableUSBStorageDevices` would written list of `Device` objects if available otherwise empty list would be returned. This method does not take any arguments.

#### getUSBDeviceByPropertyName(propertyName<string>, value<string|number>)
#### getUSBStorageDeviceByPropertyName(propertyName<string>, value<string|number>)
This method takes two arguments. The `propertyName` could be any of the `Device` properties. The `value` should be the actual value of the property. This method returns `Device` object if the property/value passed matches any of the available usb storage devices.


Expand Down Expand Up @@ -131,11 +131,11 @@ usbspy.spyOn().then(function() {
console.log(data);
});
console.log(usbspy.getAvailableUSBDevices());
console.log(usbspy.getAvailableUSBStorageDevices());
console.log(usbspy.getUSBDeviceByPropertyName('device_letter', 'D:\\'));
console.log(usbspy.getUSBStorageDeviceByPropertyName('device_letter', 'D:\\'));
console.log(usbspy.getUSBDeviceByPropertyName('device_number', 1));
console.log(usbspy.getUSBStorageDeviceByPropertyName('device_number', 1));
});
setTimeout(() => {
Expand Down
20 changes: 10 additions & 10 deletions example/test.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
var usbspy = require('../index');

usbspy.spyOn().then(function() {
usbspy.spyOn().then(function () {

usbspy.on('change', function(data) {
usbspy.on('change', function (data) {
console.log(data);
});
usbspy.on('end', function(data) {

usbspy.on('end', function (data) {
console.log(data);
});

console.log(usbspy.getAvailableUSBDevices());
console.log(usbspy.getAvailableUSBStorageDevices());

console.log(usbspy.getUSBDeviceByPropertyName('device_letter', 'D:\\'));
console.log(usbspy.getUSBStorageDeviceByPropertyName('device_letter', 'D:\\'));

console.log(usbspy.getUSBDeviceByPropertyName('device_number', 1));
console.log(usbspy.getUSBStorageDeviceByPropertyName('device_number', 1));
});

// console.log(usbspy.getUSBDeviceByPropertyName('serial_number', 'known serial number for the product'));
// console.log(usbspy.getUSBStorageDeviceByPropertyName('serial_number', 'known serial number for the product'));

// console.log(usbspy.getUSBDeviceByPropertyName('product_id', 'known product id for the vendor'));
// console.log(usbspy.getUSBStorageDeviceByPropertyName('product_id', 'known product id for the vendor'));

// console.log(usbspy.getUSBDeviceByPropertyName('vendor_id', 'known vendor id'));
// console.log(usbspy.getUSBStorageDeviceByPropertyName('vendor_id', 'known vendor id'));

// setTimeout(function() {
// usbspy.spyOff();
Expand Down
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ if (global[index.name] && global[index.name].version === index.version) {
var ready = false;

usbspy.spyOn = function (callback) {
var promise = new Promise(function(resolve, reject) {
var promise = new Promise(function (resolve, reject) {
console.log(ready);
if (!ready) {
usbspyBinding.spyOn(function (data) {
usbspy.emit('change', data);
}, function (data) {
usbspy.emit('end', data);
}, function() {
}, function () {
resolve(true);
callback(true);
});
Expand All @@ -30,7 +30,7 @@ if (global[index.name] && global[index.name].version === index.version) {
callback(false);
}
});

return promise;
}

Expand All @@ -41,16 +41,16 @@ if (global[index.name] && global[index.name].version === index.version) {
}
}

usbspy.getAvailableUSBDevices = function () {
return usbspyBinding.getAvailableUSBDevices();
usbspy.getAvailableUSBStorageDevices = function () {
return usbspyBinding.getAvailableUSBStorageDevices();
};

usbspy.getUSBDeviceByPropertyName = function (propertyName, value) {
return usbspyBinding.getUSBDeviceByPropertyName(propertyName, value);
usbspy.getUSBStorageDeviceByPropertyName = function (propertyName, value) {
return usbspyBinding.getUSBStorageDeviceByPropertyName(propertyName, value);
};

usbspy.version = index.version;
global[index.name] = usbspy;
global[index.name] = usbspy;

module.exports = usbspy;
module.exports = usbspy;
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "node-usbspy",
"version": "1.1.0",
"version": "1.1.2",
"description": "An event based node.js c++ addon/binding to retrive the connected usb storage devices and detect the storage device insertion/removal and notify the subscribed apps",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "node-gyp rebuild"
"install": "node-gyp rebuild"
},
"keywords": [
"usb",
Expand Down Expand Up @@ -33,4 +33,4 @@
"nan": "^2.8.0",
"es6-promise": "^4.2.2"
}
}
}
4 changes: 2 additions & 2 deletions src/usbs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Device *GetDeviceToBeRemoved(std::list<std::string> keys)
return deviceToBeRemoved;
}

std::list<Device *> GetUSBDevices()
std::list<Device *> GetUSBStorageDevices()
{
std::list<Device *> deviceList = {};
Device *device;
Expand Down Expand Up @@ -104,7 +104,7 @@ USBProperties ResolveUSBProperty(std::string property_name) {
return InvaildProperty;
}

Device *GetUSBDeviceByPropertyName(std::string property_name, std::string value)
Device *GetUSBStorageDeviceByPropertyName(std::string property_name, std::string value)
{
Device *device = NULL;
std::map<std::string, Device *>::iterator it;
Expand Down
4 changes: 2 additions & 2 deletions src/usbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ Device *GetDevice(std::string key);
void RemoveDevice(Device *item);
void AddDevice(Device *item);
Device *GetDeviceToBeRemoved(std::list<std::string> keys);
Device *GetUSBDeviceByPropertyName(std::string property_name, std::string value);
std::list<Device *> GetUSBDevices();
Device *GetUSBStorageDeviceByPropertyName(std::string property_name, std::string value);
std::list<Device *> GetUSBStorageDevices();
void ClearUSBDeviceList();

#endif
14 changes: 7 additions & 7 deletions src/usbspy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ NAN_METHOD(SpyOff)
cv.notify_one();
}

NAN_METHOD(GetAvailableUSBDevices)
NAN_METHOD(GetAvailableUSBStorageDevices)
{
std::list<Device *> usbs = GetUSBDevices();
std::list<Device *> usbs = GetUSBStorageDevices();
v8::Local<v8::Array> result = Nan::New<v8::Array>(usbs.size());

std::list<Device *>::iterator it;
Expand All @@ -101,17 +101,17 @@ NAN_METHOD(GetAvailableUSBDevices)
info.GetReturnValue().Set(result);
}

NAN_METHOD(GetUSBDeviceByPropertyName)
NAN_METHOD(GetUSBStorageDeviceByPropertyName)
{
if (info.Length() < 2)
{
return Nan::ThrowSyntaxError("getUSBDeviceByPropertyName function should called with paramters property_name and the corresponding value.");
return Nan::ThrowSyntaxError("getUSBStorageDeviceByPropertyName function should called with paramters property_name and the corresponding value.");
}

std::string property_name(*v8::String::Utf8Value(info[0]->ToString()));
std::string value(*v8::String::Utf8Value(info[1]->ToString()));

Device *device = GetUSBDeviceByPropertyName(property_name, value);
Device *device = GetUSBStorageDeviceByPropertyName(property_name, value);

info.GetReturnValue().Set(Preparev8Object(device));
}
Expand All @@ -120,8 +120,8 @@ NAN_MODULE_INIT(Init)
{
Set(target, New<v8::String>("spyOn").ToLocalChecked(), New<v8::FunctionTemplate>(SpyOn)->GetFunction());
Set(target, New<v8::String>("spyOff").ToLocalChecked(), New<v8::FunctionTemplate>(SpyOff)->GetFunction());
Set(target, New<v8::String>("getAvailableUSBDevices").ToLocalChecked(), New<v8::FunctionTemplate>(GetAvailableUSBDevices)->GetFunction());
Set(target, New<v8::String>("getUSBDeviceByPropertyName").ToLocalChecked(), New<v8::FunctionTemplate>(GetUSBDeviceByPropertyName)->GetFunction());
Set(target, New<v8::String>("getAvailableUSBStorageDevices").ToLocalChecked(), New<v8::FunctionTemplate>(GetAvailableUSBStorageDevices)->GetFunction());
Set(target, New<v8::String>("getUSBStorageDeviceByPropertyName").ToLocalChecked(), New<v8::FunctionTemplate>(GetUSBStorageDeviceByPropertyName)->GetFunction());
StartSpying();
}

Expand Down
2 changes: 1 addition & 1 deletion src/usbspy_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ Device *GetUSBDeviceDetails(bool adjustDeviceList)
if (drives_bitmask & (1 << drive))
{
_stprintf(drive_letter, _T("%c:\\"), 'A' + drive);
device = GetUSBDeviceByPropertyName("device_letter", drive_letter);
device = GetUSBStorageDeviceByPropertyName("device_letter", drive_letter);

if (GetDriveType(drive_letter) == DRIVE_REMOVABLE)
{
Expand Down

0 comments on commit 0a2f866

Please sign in to comment.