Skip to content

获取我的订阅主题 - PubSubGetMyTopics

函数简介

获取当前 Pub/Sub 句柄的订阅主题信息(JSON)。

接口名称

PubSubGetMyTopics

DLL调用

c
char* PubSubGetMyTopics(int64_t instance, int64_t client);

参数说明

参数名类型说明
instance长整数型OLA 实例句柄。
client长整数型Pub/Sub 句柄。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// type=1 CLIENT, connect_type=1 TCP;回调传 nullptr 表示仅发布
long pubsub = ola.PubSubNew(1, 1, "127.0.0.1", 18890, nullptr);
if (pubsub > 0) {
    ola.PubSubSub(pubsub, "topic/demo");
    std::string topics = ola.PubSubGetMyTopics(pubsub);
    ola.PubSubFree(pubsub);
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
// type=1 CLIENT, connect_type=1 TCP
long pubsub = ola.PubSubNew(1, 1, "127.0.0.1", 18890, null);
if (pubsub > 0)
{
    ola.PubSubSub(pubsub, "topic/demo");
    string topics = ola.PubSubGetMyTopics(pubsub);
    ola.PubSubFree(pubsub);
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
pubsub = ola.PubSubNew(1, 1, "127.0.0.1", 18890, None)
if pubsub > 0:
    ola.PubSubSub(pubsub, "topic/demo")
    topics = ola.PubSubGetMyTopics(pubsub)
    ola.PubSubFree(pubsub)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
long pubsub = ola.PubSubNew(1, 1, "127.0.0.1", 18890, null);
if (pubsub > 0) {
    ola.PubSubGetMyTopics(pubsub);
    ola.PubSubFree(pubsub);
}
cpp
var ola = com("OlaPlug.OlaSoft")
var pubsub = ola.PubSubNew(1, 1, "127.0.0.1", 18890, 0)
if(pubsub > 0) {
    ola.PubSubGetMyTopics(pubsub);
    ola.PubSubFree(pubsub)
}
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
pubsub = ola.PubSubNew(1, 1, "127.0.0.1", 18890, 0)
If pubsub > 0 Then
    ola.PubSubGetMyTopics(pubsub);
    ola.PubSubFree(pubsub)
End If
text
.局部变量 ola, OLAPlug
ola.创建 ()
pubsub = ola.PubSubNew (1, 1, "127.0.0.1", 18890, 0)
.如果真 (pubsub > 0)
    ola.PubSubGetMyTopics(pubsub);
    ola.PubSubFree (pubsub)
.如果真结束
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var pubsub = ola.PubSubNew(1, 1, "127.0.0.1", 18890, null);
if(pubsub > 0){
    ola.PubSubGetMyTopics(pubsub);
    ola.PubSubFree(pubsub);
}
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 pubsub = ola.PubSubNew(1, 1, "127.0.0.1", 18890, 0)
如果真 (pubsub > 0)
{
    ola.PubSubGetMyTopics(pubsub);
    ola.PubSubFree(pubsub)
}
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long pubsub = ola.PubSubNew(1, 1, "127.0.0.1", 18890, nullptr);
if (pubsub > 0) {
    ola.PubSubGetMyTopics(pubsub);
    ola.PubSubFree(pubsub);
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long pubsub = PubSubNew(instance, 1, 1, "127.0.0.1", 18890, 0);
if (pubsub > 0) {
    PubSubSub(instance, pubsub, "topic/demo");
    long ptr = PubSubGetMyTopics(instance, pubsub);
    PubSubFree(instance, pubsub);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long PubSubNew(long ola, int type, int connect_type, string ip, int port, long callback);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int PubSubFree(long ola, long client);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int PubSubSub(long ola, long client, string topic);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long PubSubGetMyTopics(long ola, long client);

long instance = CreateCOLAPlugInterFace();
long pubsub = PubSubNew(instance, 1, 1, "127.0.0.1", 18890, 0);
if (pubsub > 0) {
    PubSubSub(instance, pubsub, "topic/demo");
    long ptr = PubSubGetMyTopics(instance, pubsub);
    PubSubFree(instance, pubsub);
}
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
pubsub = ola.PubSubNew(instance, 1, 1, b"127.0.0.1", 18890)
if pubsub:
    ola.PubSubSub(instance, pubsub, "topic/demo");
    long ptr = ola.PubSubGetMyTopics(instance, pubsub);
    ola.PubSubFree(instance, pubsub)

返回值

返回值说明
(返回值)JSON 字符串指针,失败返回 0

注意事项

项目说明
释放内存返回值需要调用 FreeStringPtr 释放。