moonohos_ohos

    HarmonyOS platform packages (HiLog, RawFile, task cancellation, device info, network state, vibrator) for MoonOHOS native modules.

    harmonyos
    hilog
    rawfile
    deviceinfo
    vibrator
    native
    Download zip
    Author
    Version
    0.6.0
    License
    Apache-2.0
    Last updated
    4 days ago
    Downloads
    57

    No dependencies

    #moonohos_ohos

    HarmonyOS platform packages for MoonOHOS native modules.

    PackagePurposeNDK library
    shop1111/moonohos_ohos/hilogLogger::new(domain, tag) with debug/info/warn/error/fatal; messages are passed as a %{public}s argument, never as the format stringlibhilog_ndk.z.so
    shop1111/moonohos_ohos/rawfileread, read_text, list for packaged resources/rawfile files through a borrowed Manager (adapted from ArkTS resourceManager)librawfile.z.so
    shop1111/moonohos_ohos/taskcancelled() / check() observe the CancelToken of the running MoonOHOS async task—
    shop1111/moonohos_ohos/deviceinfoget(field), snapshot(), sdk_api_version(): device type, brand, model, OS name and version (deviceinfo.h)libdeviceinfo_ndk.z.so
    shop1111/moonohos_ohos/netconnhas_default_network(), is_metered(); needs ohos.permission.GET_NETWORK_INFOlibnet_connection.so
    shop1111/moonohos_ohos/vibratorvibrate(ms, usage=Touch), cancel(); needs ohos.permission.VIBRATElibohvibrator.z.so

    Each package carries a moonohos.native.json descriptor, so the MoonOHOS CLI cross-compiles its C stub for arm64-v8a and x86_64 and records it in the package manifest. Without the bridge (moon test on Windows/Linux/macOS) the stubs use host fallbacks: HiLog prints to stderr, rawfile.host_manager(dir) reads a directory, task.host_set_cancelled simulates cancellation, deviceinfo reports placeholders (is_device() is false), netconn.set_host_state sets what is reported, and vibrator.host_observations records calls.

    Errors carry the NDK error code; code 201 (permission denied) names the missing permission.

    /// Counts packaged documents on a worker thread, logging progress.
    pub fn count_documents(resources : @rawfile.Manager, dir : String) -> Int raise {
    let log = @hilog.Logger::new(0x4d4f, "MySearch")
    let mut characters = 0
    for name in @rawfile.list(resources, dir) {
    @task.check()
    characters += @rawfile.read_text(resources, dir + "/" + name).length()
    }
    log.info("indexed " + dir + ": " + characters.to_string() + " characters")
    characters
    }

    Toolchain: moonc >= 0.10.16 (tested with v0.10.18+6c83a7f62), HarmonyOS SDK API 26 or newer. License: Apache-2.0.