/* * Copyright 2017 balena.io * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include "drivelist.hpp" using v8::String; using v8::Number; using v8::Boolean; using v8::Local; using v8::Value; using Nan::New; namespace Drivelist { v8::Local PackDriveDescriptor(const DeviceDescriptor *instance) { v8::Local object = Nan::New(); Nan::Set(object, New("enumerator").ToLocalChecked(), New(instance->enumerator).ToLocalChecked()); Nan::Set(object, New("busType").ToLocalChecked(), New(instance->busType).ToLocalChecked()); Local busVersion = instance->busVersionNull ? (Local)Nan::Null() : (Local)New(instance->busVersion).ToLocalChecked(); Nan::Set(object, New("busVersion").ToLocalChecked(), busVersion); Nan::Set(object, New("device").ToLocalChecked(), New(instance->device).ToLocalChecked()); Local devicePath = instance->devicePathNull ? (Local)Nan::Null() : (Local)New(instance->devicePath).ToLocalChecked(); Nan::Set(object, New("devicePath").ToLocalChecked(), devicePath); Nan::Set(object, New("raw").ToLocalChecked(), New(instance->raw).ToLocalChecked()); Nan::Set(object, New("description").ToLocalChecked(), New(instance->description).ToLocalChecked()); if (instance->error != "") { Nan::Set(object, New("error").ToLocalChecked(), New(instance->error).ToLocalChecked()); } else { Nan::Set(object, New("error").ToLocalChecked(), Nan::Null()); } Nan::Set(object, New("size").ToLocalChecked(), New(static_cast(instance->size))); Nan::Set(object, New("blockSize").ToLocalChecked(), New(static_cast(instance->blockSize))); Nan::Set(object, New("logicalBlockSize").ToLocalChecked(), New(static_cast(instance->logicalBlockSize))); v8::Local mountpoints = Nan::New(); uint32_t index = 0; for (std::string mountpointPath : instance->mountpoints) { v8::Local mountpoint = Nan::New(); Nan::Set(mountpoint, New("path").ToLocalChecked(), New(mountpointPath).ToLocalChecked()); if (index < instance->mountpointLabels.size()) { Nan::Set(mountpoint, New("label").ToLocalChecked(), New(instance->mountpointLabels[index]).ToLocalChecked()); } Nan::Set(mountpoints, index, mountpoint); index++; } Nan::Set(object, New("mountpoints").ToLocalChecked(), mountpoints); Nan::Set(object, New("isReadOnly").ToLocalChecked(), New(instance->isReadOnly)); Nan::Set(object, New("isSystem").ToLocalChecked(), New(instance->isSystem)); Nan::Set(object, New("isVirtual").ToLocalChecked(), New(instance->isVirtual)); Nan::Set(object, New("isRemovable").ToLocalChecked(), New(instance->isRemovable)); Nan::Set(object, New("isCard").ToLocalChecked(), New(instance->isCard)); Nan::Set(object, New("isSCSI").ToLocalChecked(), New(instance->isSCSI)); Nan::Set(object, New("isUSB").ToLocalChecked(), New(instance->isUSB)); Local isUAS = instance->isUASNull ? (Local)Nan::Null() : (Local)New(instance->isUAS); Nan::Set(object, New("isUAS").ToLocalChecked(), isUAS); return object; } } // namespace Drivelist