@ohos-ports/drivelist 12.0.2-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ /*
2
+ * Copyright 2017 balena.io
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #include "drivelist.hpp"
18
+
19
+ #include <napi.h>
20
+
21
+ #include <vector>
22
+
23
+ class DriveListWorker : public Napi::AsyncWorker {
24
+ public:
25
+ explicit DriveListWorker(Napi::Function& callback)
26
+ : Napi::AsyncWorker(callback), devices() {}
27
+
28
+ virtual ~DriveListWorker() {}
29
+
30
+ void Execute() { devices = Drivelist::ListStorageDevices(); }
31
+
32
+ void OnOK() {
33
+ Napi::HandleScope scope(Env());
34
+ Napi::Object drives = Napi::Array::New(Env());
35
+
36
+ uint32_t i;
37
+ uint32_t size = (uint32_t)devices.size();
38
+
39
+ for (i = 0; i < size; i++) {
40
+ drives.Set(i, Drivelist::PackDriveDescriptor(Env(), &devices[i]));
41
+ }
42
+
43
+ Callback().Call({Env().Undefined(), drives});
44
+ }
45
+
46
+ private:
47
+ std::vector<Drivelist::DeviceDescriptor> devices;
48
+ };
49
+
50
+ Napi::Value List(const Napi::CallbackInfo& info) {
51
+ if (!info[0].IsFunction()) {
52
+ Napi::TypeError::New(info.Env(), "Callback must be a function")
53
+ .ThrowAsJavaScriptException();
54
+ return info.Env().Null();
55
+ }
56
+
57
+ Napi::Function callback = info[0].As<Napi::Function>();
58
+ DriveListWorker* dlWorker = new DriveListWorker(callback);
59
+ dlWorker->Queue();
60
+
61
+ return info.Env().Undefined();
62
+ }
63
+
64
+ Napi::Object Init(Napi::Env env, Napi::Object exports) {
65
+ exports.Set(Napi::String::New(env, "list"), Napi::Function::New(env, List));
66
+ return exports;
67
+ }
68
+
69
+ NODE_API_MODULE(DriveList, Init)
@@ -0,0 +1,65 @@
1
+ /*
2
+ * Copyright 2017 balena.io
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #ifndef SRC_DRIVELIST_HPP_
18
+ #define SRC_DRIVELIST_HPP_
19
+
20
+ #include <napi.h>
21
+ #include <string>
22
+ #include <vector>
23
+
24
+ namespace Drivelist {
25
+
26
+ struct MountPoint {
27
+ std::string path;
28
+ };
29
+
30
+ struct DeviceDescriptor {
31
+ std::string enumerator;
32
+ std::string busType;
33
+ std::string busVersion;
34
+ bool busVersionNull;
35
+ std::string device;
36
+ std::string devicePath;
37
+ bool devicePathNull;
38
+ std::string raw;
39
+ std::string description;
40
+ std::string error;
41
+ std::string partitionTableType;
42
+ uint64_t size;
43
+ uint32_t blockSize = 512;
44
+ uint32_t logicalBlockSize = 512;
45
+ std::vector<std::string> mountpoints;
46
+ std::vector<std::string> mountpointLabels;
47
+ bool isReadOnly; // Device is read-only
48
+ bool isSystem; // Device is a system drive
49
+ bool isVirtual; // Device is a virtual storage device
50
+ bool isRemovable; // Device is removable from the running system
51
+ bool isCard; // Device is an SD-card
52
+ bool isSCSI; // Connected via the Small Computer System Interface (SCSI)
53
+ bool isUSB; // Connected via Universal Serial Bus (USB)
54
+ bool isUAS; // Connected via the USB Attached SCSI (UAS)
55
+ bool isUASNull;
56
+ };
57
+
58
+ std::vector<DeviceDescriptor> ListStorageDevices();
59
+ Napi::Object PackDriveDescriptor(Napi::Env env, const DeviceDescriptor *instance);
60
+
61
+ } // namespace Drivelist
62
+
63
+ Napi::Value List(const Napi::CallbackInfo& info);
64
+
65
+ #endif // SRC_DRIVELIST_HPP_
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Copyright 2017 balena.io
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #include <napi.h>
18
+ #include <uv.h>
19
+ #include "../drivelist.hpp"
20
+
21
+ namespace Drivelist {
22
+
23
+ // TODO(jhermsmeier): Implement
24
+ std::vector<DeviceDescriptor> ListStorageDevices() {
25
+ std::vector<DeviceDescriptor> drivelist;
26
+ return drivelist;
27
+ }
28
+
29
+ } // namespace Drivelist