示例#1
0
    void WriteToRepo(IntPtr h, System.String name, System.String content)
    {
        print("Writing " + name + " to repo: " + content);

        int res;

        IntPtr cb  = Egal.ccn_charbuf_create();
        IntPtr nm  = Egal.ccn_charbuf_create();
        IntPtr cmd = Egal.ccn_charbuf_create();

        Egal.ccn_name_from_uri(nm, name);
        Egal.ccn_create_version(h, nm, VersioningFlags.CCN_V_NOW, 0, 0);

        NormalStruct Data  = new NormalStruct(nm, cb, h, content.Length, content);
        IntPtr       pData = Marshal.AllocHGlobal(Marshal.SizeOf(Data));

        Marshal.StructureToPtr(Data, pData, true);

        IntPtr template = Egal.SyncGenInterest(IntPtr.Zero, 1, 4, -1, -1, IntPtr.Zero);

        Egal.ccn_closure Action = new Egal.ccn_closure(WriteCallback, pData, 0);
        IntPtr           pnt    = Marshal.AllocHGlobal(Marshal.SizeOf(Action));

        Marshal.StructureToPtr(Action, pnt, true);

        res = Egal.ccn_set_interest_filter(h, nm, pnt);         // listen: interest

        res = Egal.ccn_charbuf_append_charbuf(cmd, nm);
        res = Egal.ccn_name_from_uri(cmd, "%C1.R.sw");
        Egal.ccn_name_append_nonce(cmd);

        counter_for_run++;
        res = Egal.ccn_set_run_timeout(h, 0);
        Egal.ccn_express_interest(h, cmd, pnt, template);         // express interest
        counter_for_run--;

        return;
    }