blob: b3b9e3bacad380522fe3cf6236095b191cec370e [file] [log] [blame]
andrewsbrown1f28bcf2015-04-20 13:29:20 -07001/*
2 * jndn-mock
3 * Copyright (c) 2015, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU Lesser General Public License,
7 * version 3, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
12 * more details.
13 */
14package com.intel.jndn.mock;
15
16import java.io.IOException;
17import java.nio.ByteBuffer;
Alexander Afanasyev8e9330f2016-01-25 19:13:40 -080018
19import net.named_data.jndn.*;
andrewsbrown1f28bcf2015-04-20 13:29:20 -070020import net.named_data.jndn.encoding.EncodingException;
21import net.named_data.jndn.encoding.WireFormat;
22import net.named_data.jndn.util.Blob;
23
24/**
25 * Provides help for extending {@link Face}; this should be an interface but
26 * until it is we need a way to know what is the minimal set of methods to
27 * override.
28 *
29 * @author Andrew Brown <andrew.brown@intel.com>
30 */
31public abstract class FaceExtension extends Face {
32
33 public long expressInterest(Interest interest, OnData onData, OnTimeout onTimeout,
34 WireFormat wireFormat) throws IOException {
35 return expressInterest(interest, onData, onTimeout, wireFormat);
36 }
37
38 public long expressInterest(Interest interest, OnData onData, OnTimeout onTimeout) throws IOException {
39 return expressInterest(interest, onData, onTimeout, WireFormat.getDefaultWireFormat());
40 }
41
42 public long expressInterest(Interest interest, OnData onData, WireFormat wireFormat) throws IOException {
43 return expressInterest(interest, onData, null, wireFormat);
44 }
45
46 public long expressInterest(Interest interest, OnData onData) throws IOException {
47 return expressInterest(interest, onData, null, WireFormat.getDefaultWireFormat());
48 }
49
50 public long expressInterest(Name name, Interest interestTemplate, OnData onData, OnTimeout onTimeout,
51 WireFormat wireFormat) throws IOException {
52 Interest interest = new Interest(name);
53 if (interestTemplate != null) {
54 interest.setMinSuffixComponents(interestTemplate.getMinSuffixComponents());
55 interest.setMaxSuffixComponents(interestTemplate.getMaxSuffixComponents());
56 interest.setKeyLocator(interestTemplate.getKeyLocator());
57 interest.setExclude(interestTemplate.getExclude());
58 interest.setChildSelector(interestTemplate.getChildSelector());
59 interest.setMustBeFresh(interestTemplate.getMustBeFresh());
andrewsbrown1f28bcf2015-04-20 13:29:20 -070060 interest.setInterestLifetimeMilliseconds(
61 interestTemplate.getInterestLifetimeMilliseconds());
62 } else {
63 interest.setInterestLifetimeMilliseconds(4000.0);
64 }
65
66 return expressInterest(interest, onData, onTimeout, wireFormat);
67 }
68
69 public abstract long registerPrefix(Name prefix,
Alexander Afanasyev8e9330f2016-01-25 19:13:40 -080070 OnInterestCallback onInterest, OnRegisterFailed onRegisterFailed,
71 OnRegisterSuccess onRegisterSuccess, ForwardingFlags flags,
72 WireFormat wireFormat) throws IOException, net.named_data.jndn.security.SecurityException;
andrewsbrown1f28bcf2015-04-20 13:29:20 -070073
74 public abstract void removeRegisteredPrefix(long registeredPrefixId);
75
76 public abstract long setInterestFilter(InterestFilter filter, OnInterestCallback onInterest);
77
78 public long setInterestFilter(Name prefix, OnInterestCallback onInterest) {
79 return setInterestFilter(new InterestFilter(prefix), onInterest);
80 }
81
82 public abstract void unsetInterestFilter(long interestFilterId);
83
84 public abstract void putData(Data data, WireFormat wireFormat) throws IOException;
85
86 public void putData(Data data) throws IOException {
87 putData(data, WireFormat.getDefaultWireFormat());
88 }
89
90 public abstract void send(ByteBuffer encoding) throws IOException;
91
92 public void send(Blob encoding) throws IOException {
93 send(encoding.buf());
94 }
95
96 public abstract void processEvents() throws IOException, EncodingException;
97
98 public abstract boolean isLocal() throws IOException;
99
100 public abstract void shutdown();
101}