0004-Add-factory-singleton-for-participitants_685072f.patch
rsb-cil-test/Program.cs | ||
---|---|---|
74 | 74 | |
75 | 75 |
listener.Deactivate(); |
76 | 76 | |
77 |
Console.WriteLine("\nConverter test:");
|
|
77 |
Console.WriteLine("\nRepository test with factory:");
|
|
78 | 78 | |
79 |
DefaultConverterRepository.Instance.addConverter(new ProtocolBufferConverter(JointAngles.Descriptor)); |
|
79 |
Factory.Instance.Host = host; |
|
80 |
Factory.Instance.Port = port; |
|
80 | 81 | |
81 |
Informer repoInformer = new Informer("/test/repo", new OutConnector(new BusClientConnection(host, port), DefaultConverterRepository.Instance.SerializationConverterSelector)); |
|
82 |
Listener repoListener = new Listener(new InPushConnector(new BusClientConnection(host, port), new Scope("/"), DefaultConverterRepository.Instance.DeserializationConverterSelector)); |
|
82 |
DefaultConverterRepository.Instance.addConverter(new ProtocolBufferConverter(JointAngles.Descriptor)); |
|
83 | 83 | |
84 |
repoListener.EventReceived += (e) => |
|
85 |
{ |
|
84 |
Informer repoInformer = Factory.Instance.createInformer("/test/repo"); |
|
85 |
Listener repoListener = Factory.Instance.createListener("/"); |
|
86 |
|
|
87 |
repoListener.EventReceived += (e) => { |
|
86 | 88 |
Console.WriteLine("Event: {0}\nData: {1}", e, e.Data); |
87 | 89 |
}; |
88 | 90 |
repoListener.Activate(); |
rsb-cil/Rsb/Factory.cs | ||
---|---|---|
1 |
|
|
2 | ||
3 |
using Rsb.Transport.Socket; |
|
4 |
using Rsb.Converter; |
|
5 | ||
6 |
using System; |
|
7 | ||
8 |
namespace Rsb |
|
9 |
{ |
|
10 |
public class Factory |
|
11 |
{ |
|
12 |
private static readonly Factory instance = new Factory(); |
|
13 | ||
14 |
private byte[] host = {127,0,0,1}; |
|
15 |
public byte[] Host { |
|
16 |
get { return host; } |
|
17 |
set { |
|
18 |
if (value.Length != 4) throw new ArgumentException("A IPv4 adress has to have exactly 4 bytes"); |
|
19 |
host = value; |
|
20 |
} |
|
21 |
} |
|
22 |
private int port = 30010; |
|
23 |
public int Port { get { return port; } set { port = value; } } |
|
24 | ||
25 |
// Explicit static constructor to tell C# compiler |
|
26 |
// not to mark type as beforefieldinit |
|
27 |
static Factory() |
|
28 |
{ |
|
29 |
} |
|
30 | ||
31 |
private Factory() |
|
32 |
{ |
|
33 |
} |
|
34 | ||
35 |
public static Factory Instance |
|
36 |
{ |
|
37 |
get |
|
38 |
{ |
|
39 |
return instance; |
|
40 |
} |
|
41 |
} |
|
42 | ||
43 |
public Informer createInformer(Scope scope) { |
|
44 |
return new Informer(scope, |
|
45 |
new OutConnector( |
|
46 |
new BusClientConnection(host, port), |
|
47 |
DefaultConverterRepository.Instance.SerializationConverterSelector)); |
|
48 |
} |
|
49 | ||
50 |
public Informer createInformer(string scope) { |
|
51 |
return createInformer(new Scope(scope)); |
|
52 |
} |
|
53 | ||
54 |
public Listener createListener(Scope scope) |
|
55 |
{ |
|
56 |
return new Listener( |
|
57 |
new InPushConnector( |
|
58 |
new BusClientConnection(host, port), |
|
59 |
scope, |
|
60 |
DefaultConverterRepository.Instance.DeserializationConverterSelector |
|
61 |
)); |
|
62 |
} |
|
63 | ||
64 |
public Listener createListener(string scope) { |
|
65 |
return createListener(new Scope(scope)); |
|
66 |
} |
|
67 | ||
68 |
} |
|
69 |
} |
rsb-cil/rsb-cil.csproj | ||
---|---|---|
51 | 51 |
<Compile Include="Rsb\Converter\StringConverter.cs" /> |
52 | 52 |
<Compile Include="Rsb\Converter\UInt32Converter.cs" /> |
53 | 53 |
<Compile Include="Rsb\Converter\UInt64Converter.cs" /> |
54 |
<Compile Include="Rsb\Factory.cs" /> |
|
54 | 55 |
<Compile Include="Rsb\Protocol\EventId.cs" /> |
55 | 56 |
<Compile Include="Rsb\Protocol\EventMetaData.cs" /> |
56 | 57 |
<Compile Include="Rsb\Protocol\Notification.cs" /> |
57 |
- |