0002-Add-factory-singleton-for-participants_d138e5f.patch
rsb-cil-test/Program.cs | ||
---|---|---|
74 | 74 | |
75 | 75 |
listener.Deactivate(); |
76 | 76 | |
77 |
Console.WriteLine("\nConverter test:"); |
|
77 |
Console.WriteLine("\nFactory Test:"); |
|
78 | ||
79 |
Factory.Instance.Hostname = "localhost"; |
|
80 |
Factory.Instance.Port = port; |
|
78 | 81 | |
79 | 82 |
DefaultConverterRepository.Instance.addConverter(new ProtocolBufferConverter(JointAngles.Descriptor)); |
80 | 83 | |
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));
|
|
84 |
Informer repoInformer = Factory.Instance.CreateInformer("/test/repo");
|
|
85 |
Listener repoListener = Factory.Instance.CreateListener("/");
|
|
83 | 86 | |
84 | 87 |
repoListener.EventReceived += (e) => |
85 | 88 |
{ |
rsb-cil/Rsb/Factory.cs | ||
---|---|---|
1 |
using Rsb.Transport.Socket; |
|
2 |
using Rsb.Converter; |
|
3 | ||
4 |
namespace Rsb |
|
5 |
{ |
|
6 |
public class Factory |
|
7 |
{ |
|
8 |
private static readonly Factory instance = new Factory(); |
|
9 | ||
10 |
public string Hostname = "localhost"; |
|
11 |
public int Port = 30010; |
|
12 | ||
13 |
// Explicit static constructor to tell C# compiler |
|
14 |
// not to mark type as beforefieldinit |
|
15 |
static Factory() |
|
16 |
{ |
|
17 |
} |
|
18 | ||
19 |
private Factory() |
|
20 |
{ |
|
21 |
} |
|
22 | ||
23 |
public static Factory Instance |
|
24 |
{ |
|
25 |
get |
|
26 |
{ |
|
27 |
return instance; |
|
28 |
} |
|
29 |
} |
|
30 | ||
31 |
public Informer CreateInformer(Scope scope) { |
|
32 | ||
33 |
return new Informer(scope, |
|
34 |
new OutConnector( |
|
35 |
new BusClientConnection(Hostname, Port), |
|
36 |
DefaultConverterRepository.Instance.SerializationConverterSelector)); |
|
37 |
} |
|
38 | ||
39 |
public Informer CreateInformer(string scope) { |
|
40 |
return CreateInformer(new Scope(scope)); |
|
41 |
} |
|
42 | ||
43 |
public Listener CreateListener(Scope scope) |
|
44 |
{ |
|
45 | ||
46 |
return new Listener( |
|
47 |
new InPushConnector( |
|
48 |
new BusClientConnection(Hostname, Port), |
|
49 |
scope, |
|
50 |
DefaultConverterRepository.Instance.DeserializationConverterSelector |
|
51 |
)); |
|
52 |
} |
|
53 | ||
54 |
public Listener CreateListener(string scope) { |
|
55 |
return CreateListener(new Scope(scope)); |
|
56 |
} |
|
57 | ||
58 |
} |
|
59 |
} |
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 |
- |