var dlfcn = require("dlfcna.js");
//console.log(dlfcn)

var funcs = [
    ["set", "viiiiii"],
    ["isRTC", "is"],
];

//console.log("in factory_rtc.js")
function register() {
    //console.log("will register rtc.so")
    var isSuccess = dlfcn.register("@native.rtc", "./lib/factory/rtc.so", funcs);
    if (isSuccess) {
        //console.log("load so successfully")
        var rtc = require("@native.rtc");
        return rtc
    } else {
        //console.log("load so failed")
    }
    return undefined;
}
var rtc = register();

function ctrl(word, obj) {
    switch (word) {
        case "set": {
            rtc.set(obj['year'],
                obj['month'],
                obj['day'],
                obj['hour'],
                obj['minute'],
                obj['second'])
            break
        }
        default: {
            //console.log("ERROR:rtc ctrl word undefined..")
        }
    }
}
function getrtc(word) {
    switch (word) {
        case "getRTC": {
            var ret = 0
            try {
                ret = rtc.isRTC("rtc1")
            } catch (e) {
                ret = 0
                //console.log("!!!ERROR:" + e)
            }
            //console.log(ret);
            return ret
            // break
        }
        default: {
            //console.log("ERROR:rtc getRTC word undefined..")
        }
    }
}
module.exports = {
    ctrl: ctrl,
    getrtc: getrtc,
}

