46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace bts {
|
|
// This caches all the published data. This class is created and held by
|
|
// PublisherCore. When data is publsihed , PublisherCore passes it to this
|
|
// class via the publish call. On a reconnection to the PubSubServer,
|
|
// PublisherCore calls get_content to get the data to re-publish, to
|
|
// re-seed the PubSubServer
|
|
public class PublishedCache {
|
|
private Dictionary<string, SingleTagData> _data_map = new Dictionary<string, SingleTagData>();
|
|
|
|
public PublishedCache() { }
|
|
|
|
|
|
public void publish(PublishMsg msg) {
|
|
Log.Gen.info($"PublishedCache.publish msg: {msg}");
|
|
SingleTagData tag_data = null;
|
|
if (!_data_map.TryGetValue(msg.tag, out tag_data)) {
|
|
tag_data = new SingleTagData(msg.tag, msg.tag_type);
|
|
_data_map.Add(msg.tag, tag_data);
|
|
}
|
|
tag_data.handle_publish(msg);
|
|
}
|
|
|
|
public Tuple<string, byte[]> get_content(string tag) {
|
|
SingleTagData tag_data;
|
|
byte[] rv = new byte[] { };
|
|
if (_data_map.TryGetValue(tag, out tag_data)) {
|
|
string tag_type = tag_data.tag_type;
|
|
byte[] data = tag_data.get_current_content();
|
|
return new Tuple<string, byte[]>(tag_type, data);
|
|
}
|
|
return new Tuple<string, byte[]>(String.Empty, new byte[] { });
|
|
}
|
|
|
|
public void clear(string tag) {
|
|
if (_data_map.ContainsKey(tag)) {
|
|
_data_map.Remove(tag);
|
|
} else {
|
|
bts.Log.Gen.warn($"AllPublishTagState told to clear nonexisting tag: {tag} ");
|
|
}
|
|
}
|
|
}
|
|
}
|