GenInterfaceDelegatorSerializer(stream, id, decl);
GenInterfaceDelegatorDeserializer(stream, id, decl);
GenInterfaceDelegatorConstructor(stream, id, decl);
+ GenInterfaceDelegatorDisposer(stream, id, decl);
GenInterfaceDelegatorInvoker(stream, id, decl);
}
);
}
+void CProxyBodyGen::GenInterfaceDelegatorDisposer(
+ std::ofstream& stream, const std::string& id, const Declaration& decl) {
+ stream << SmartIndent(GenTemplateString(
+ ReplaceAll(CB_DELEGATE_DISPOSER, "##", id + "_" + decl.GetID()),
+ [&]()->std::string {
+ return id;
+ }));
+}
+
void CProxyBodyGen::GenInterfaceDelegatorInvoker(
std::ofstream& stream, const std::string& id, const Declaration& decl) {
const char parcel[] = "$$(parcel, $$);\n";
void GenInterfaceDelegatorConstructor(std::ofstream& stream,
const std::string& id,
const Declaration& decl);
+ void GenInterfaceDelegatorDisposer(std::ofstream& stream,
+ const std::string& id,
+ const Declaration& decl);
void GenInterfaceDelegatorInvoker(std::ofstream& stream,
const std::string& id,
const Declaration& decl);
}
)__c_cb";
+const char CB_DELEGATE_DISPOSER[] =
+R"__c_cb(
+int rpc_port_proxy_##_dispose(rpc_port_proxy_$$_h proxy, rpc_port_##_h delegate)
+{
+ struct ##_s *handle;
+ GList *iter;
+
+ if (!proxy || !delegate) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Invalid handle %p %p", proxy, delegate);
+ return -1;
+ }
+
+ iter = proxy->delegates;
+ while (iter) {
+ handle = (struct ##_s *)iter->data;
+ if (handle == delegate) {
+ proxy->delegates = g_list_remove_link(proxy->delegates, iter);
+ free(handle);
+ g_list_free(iter);
+ return 0;
+ }
+ iter = g_list_next(iter);
+ }
+
+ return -1;
+}
+)__c_cb";
+
const char CB_DELEGATE_INVOKER[] =
R"__c_cb(
static void __$$_delegate_$$(GList **list, rpc_port_parcel_h parcel, int seq_id)
void CProxyHeaderGen::GenInterface(std::ofstream& stream,
const Interface& inf) {
- GenInterfaceDelegators(stream, inf);
GenInterfaceDeclaration(stream, inf);
+ GenInterfaceDelegators(stream, inf);
GenInterfaceConnect(stream, inf);
GenInterfaceDisconnect(stream, inf);
GenInterfaceMethods(stream, inf);
);
stream << ReplaceAll(CB_DELEGATE_CTOR, "##", id + "_" + decl.GetID());
+ stream << GenTemplateString(
+ ReplaceAll(CB_DELEGATE_DISPOSER, "##", id + "_" + decl.GetID()),
+ [&]()->std::string {
+ return id;
+ });
}
void CProxyHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
R"__c_cb(
rpc_port_##_h rpc_port_##_create(## callback, bool once, void *user_data);
)__c_cb";
+
+const char CB_DELEGATE_DISPOSER[] =
+R"__c_cb(
+int rpc_port_proxy_##_dispose(rpc_port_proxy_$$_h proxy, rpc_port_##_h delegate);
+)__c_cb";
[&]()->std::string { return iface.GetID(); },
[&]()->std::string { return iface.GetID(); },
[&]()->std::string { return iface.GetID(); },
+ [&]()->std::string { return iface.GetID(); },
[&]()->std::string { return iface.GetID(); }
);
return once_;
}
+std::string $$::CallbackBase::GetTag() const {
+ return std::to_string(id_) + "::" + std::to_string(seq_id_);
+}
+
rpc_port_parcel_h operator << (rpc_port_parcel_h h, const $$::CallbackBase& cb) {
rpc_port_parcel_write_int32(h, cb.id_);
rpc_port_parcel_write_int32(h, cb.seq_id_);
int GetId() const;
int GetSeqId() const;
bool IsOnce() const;
+ std::string GetTag() const;
private:
friend rpc_port_parcel_h operator << (rpc_port_parcel_h h, const CallbackBase& cb);
[&]()->std::string { return iface.GetID(); },
[&]()->std::string { return iface.GetID(); },
[&]()->std::string { return iface.GetID(); },
+ [&]()->std::string { return iface.GetID(); },
[&]()->std::string { return iface.GetID(); }
);
stream << NLine(1);
}
}
+void $$::DisposeCallback(const std::string& tag) {
+ for (auto& i : delegate_list_) {
+ if (i->GetTag() == tag) {
+ delegate_list_.remove(i);
+ return;
+ }
+ }
+}
+
void $$::ProcessReceivedEvent(rpc_port_parcel_h parcel) {
int id = 0;
int seq_id = 0;
/// <remark> If you want to use this method, you must add privileges.</remark>
void Connect();
+ /// <summary>
+ /// Disposes delegate objects in this interface
+ /// </summary>
+ /// <param name="tag">The tag string from delegate object</param>
+ void DisposeCallback(const std::string& tag);
+
)__cpp_cb";
const char CB_PRIVATE_MEMBERS[] =
internal bool Once;
private static int _seqNum = 0;
+ public string Tag
+ {
+ get
+ {
+ return Id.ToString() + "::" + SeqId.ToString();
+ }
+ }
+
public CallbackBase(int delegateId, bool once)
{
Id = delegateId;
throw new InvalidIOException();
}
}
+
+ /// <summary>
+ /// Disposes delegate objects in this interface
+ /// </summary>
+ /// <param name="tag">The tag string from delegate object</param>
+ void DisposeCallback(string tag)
+ {
+ foreach (var i in _delegateList)
+ {
+ if (i.Tag.Equals(tag))
+ {
+ _delegateList.Remove(i);
+ return;
+ }
+ }
+ }
)__cs_cb";
const char CB_DISPOSABLE[] =