Ejemplo n.º 1
0
    int WatchOverRepo(IntPtr h, string p, string t)
    {
        // this is a C# expansion of Egal.WatchOverRepo
        int    res;
        IntPtr prefix = Egal.ccn_charbuf_create();
        IntPtr topo   = Egal.ccn_charbuf_create();

        Egal.ccn_name_init(prefix);
        Egal.ccn_name_init(topo);

        res = Egal.ccn_name_from_uri(prefix, p);
        if (res < 0)
        {
            print("Prefix not right");
            return(res);
        }

        res = Egal.ccn_name_from_uri(topo, t);
        if (res < 0)
        {
            print("Topo not right");
            return(res);
        }

        int timeout = TIMEOUT;

        if (timeout < -1)
        {
            print("Timeout cannot be less than -1");
            return(-1);
        }
        timeout *= 1000;

        IntPtr slice = Egal.ccns_slice_create();

        Egal.ccns_slice_set_topo_prefix(slice, topo, prefix);

        IntPtr ccns = Egal.ccns_open(h, slice, WatchCallback, IntPtr.Zero, IntPtr.Zero);

        // ccns_close(&ccns, NULL, NULL);

        Egal.ccns_slice_destroy(ref slice);

        return(res);
    }
Ejemplo n.º 2
0
    int WriteSlice(IntPtr h, System.String p, System.String t)
    {
        // this is a C# expansion of Egal.WriteSlice
        int    res;
        IntPtr prefix = Egal.ccn_charbuf_create();
        IntPtr topo   = Egal.ccn_charbuf_create();

        Egal.ccn_name_init(prefix);
        Egal.ccn_name_init(topo);

        res = Egal.ccn_name_from_uri(prefix, p);
        if (res < 0)
        {
            print("Prefix not right");
            return(res);
        }

        res = Egal.ccn_name_from_uri(topo, t);
        if (res < 0)
        {
            print("Topo not right");
            return(res);
        }

        int timeout = TIMEOUT;

        if (timeout < -1)
        {
            print("Timeout cannot be less than -1");
            return(-1);
        }
        timeout *= 1000;

        IntPtr slice = Egal.ccns_slice_create();

        Egal.ccns_slice_set_topo_prefix(slice, topo, prefix);

        res = Egal.ccns_write_slice(h, slice, prefix);

        Egal.ccns_slice_destroy(ref slice); // after this, slice == 0

        return(res);
    }
Ejemplo n.º 3
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;
    }
Ejemplo n.º 4
0
    int RegisterInterestFilter(IntPtr h, string name)
    {
        int    res = 0;
        IntPtr nm  = Egal.ccn_charbuf_create();

        res = Egal.ccn_name_from_uri(nm, name);
        if (res < 0)
        {
            return(res);
        }

        NormalStruct State  = new NormalStruct(nm, IntPtr.Zero, h, 0, "");
        IntPtr       pState = Marshal.AllocHGlobal(Marshal.SizeOf(State));

        Marshal.StructureToPtr(State, pState, true);

        Egal.ccn_closure Action  = new Egal.ccn_closure(PublishState, pState, 0);
        IntPtr           pAction = Marshal.AllocHGlobal(Marshal.SizeOf(Action));

        Marshal.StructureToPtr(Action, pAction, true);

        res = Egal.ccn_set_interest_filter(h, nm, pAction);
        return(res);
    }