本文整理汇总了C++中InterfaceDescription类的典型用法代码示例。如果您正苦于以下问题:C++ InterfaceDescription类的具体用法?C++ InterfaceDescription怎么用?C++ InterfaceDescription使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InterfaceDescription类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateInterface
QStatus CreateInterface(string interfaceName)
{
InterfaceDescription *intf = NULL;
QStatus status = s_msgBus->CreateInterface(interfaceName.c_str(), intf);
if (ER_OK == status) {
cout << "Created message interface" <<endl;
intf->AddMethod("on", "y", "s", "pinNum, ackStr", 0);
intf->AddMethod("off", "y", "s", "pinNum, ackStr", 0);
intf->Activate();
} else {
cout << "Could not create interface '"<< interfaceName <<"'" << endl;
}
return status;
}
示例2: main
int CDECL_CALL main()
{
if (AllJoynInit() != ER_OK) {
return 1;
}
#ifdef ROUTER
if (AllJoynRouterInit() != ER_OK) {
AllJoynShutdown();
return 1;
}
#endif
{
BusAttachment busAttachment("AddInterfaceFromCode", true);
busAttachment.Start();
/// [code_interface_adding_to_busAttachment]
InterfaceDescription* exampleIntf = NULL;
QStatus status = busAttachment.CreateInterface(::com::example::name, exampleIntf);
if (ER_OK == status) {
status = exampleIntf->AddMethod("Echo", "s", "s", "input_arg,return_arg");
}
if (ER_OK == status) {
status = exampleIntf->AddSignal("Chirp", "s", "sound", MEMBER_ANNOTATE_SESSIONCAST);
}
if (ER_OK == status) {
status = exampleIntf->AddProperty("Volume", "i", PROP_ACCESS_RW);
}
if (ER_OK == status) {
exampleIntf->Activate();
} else {
printf("Failed to create interface %s\n", ::com::example::name);
}
/// [code_interface_adding_to_busAttachment]
const InterfaceDescription* interfaceFromBus = busAttachment.GetInterface(::com::example::name);
if (interfaceFromBus == NULL) {
printf("Failed to Get %s\n", ::com::example::name);
} else {
printf("Read the %s interface back from the BusAttachment.\n%s\n", ::com::example::name, interfaceFromBus->Introspect().c_str());
}
}
#ifdef ROUTER
AllJoynRouterShutdown();
#endif
AllJoynShutdown();
return 0;
}
示例3: CreateInterfaces
bool ChatObject::CreateInterfaces()
{
const char* ifName = CHAT_SERVICE_INTERFACE_NAME;
InterfaceDescription* chatIntf = NULL;
status = ajConnection->busAttachment->CreateInterface(ifName, chatIntf);
assert(chatIntf);
if (ER_OK == status) {
chatIntf->AddSignal("Chat", "s", "str", 0);
chatIntf->Activate();
} else {
NotifyUser(MSG_ERROR, "Failed to create interface \"%s\" (%s)\n", CHAT_SERVICE_INTERFACE_NAME, QCC_StatusText(status));
return false;
}
NotifyUser(MSG_SYSTEM, "Create interface \"%s\" (%s)\n", CHAT_SERVICE_INTERFACE_NAME, QCC_StatusText(status));
return true;
}
示例4: NotifyUser
void ChatConnection::createMessageBus()
{
QStatus status = ER_OK;
NotifyUser(MSG_STATUS, "Create message bus.");
ajn::BusAttachment* bus = new BusAttachment("chat", true);
this->busAttachment = bus;
this->busListener = new MyBusListener();
this->busListener->SetListenCallback(JoinNotifier);
this->busListener->SetConnection(this);
/* Create org.alljoyn.bus.samples.chat interface */
InterfaceDescription* chatIntf;
status = bus->CreateInterface(CHAT_SERVICE_INTERFACE_NAME, chatIntf);
if (ER_OK == status) {
chatIntf->AddSignal("Chat", "s", "str", 0);
chatIntf->Activate();
} else {
NotifyUser(MSG_ERROR, "Failed to create interface \"%s\" (%s)\n", CHAT_SERVICE_INTERFACE_NAME, QCC_StatusText(status));
}
/* Create and register the bus object that will be used to send and receive signals */
ChatObject* chatObject = new ChatObject(*bus, CHAT_SERVICE_OBJECT_PATH);
this->chatObject = chatObject;
this->busAttachment->RegisterBusObject(*chatObject);
chatObject->SetConnection(this);
}
示例5: main
/** Main entry point */
int main(int argc, char** argv, char** envArg)
{
QStatus status = ER_OK;
printf("AllJoyn Library version: %s\n", ajn::GetVersion());
printf("AllJoyn Library build info: %s\n", ajn::GetBuildInfo());
/* Install SIGINT handler */
signal(SIGINT, SigIntHandler);
#ifdef _WIN32
qcc::String connectArgs = "tcp:addr=127.0.0.1,port=9956";
#else
qcc::String connectArgs = "unix:abstract=bluebus";
#endif
/* Create message bus */
g_msgBus = new BusAttachment("myApp", true);
/* Add org.alljoyn.Bus.method_sample interface */
InterfaceDescription* testIntf = NULL;
status = g_msgBus->CreateInterface(SERVICE_NAME, testIntf);
if (status == ER_OK) {
printf("Interface Created.\n");
testIntf->AddMethod("cat", "ss", "s", "inStr1,inStr2,outStr", 0);
testIntf->Activate();
} else {
printf("Failed to create interface 'org.alljoyn.Bus.method_sample'\n");
}
/* Start the msg bus */
status = g_msgBus->Start();
if (ER_OK == status) {
printf("BusAttachement started.\n");
/* Register local objects and connect to the daemon */
BasicSampleObject testObj(*g_msgBus, SERVICE_PATH);
g_msgBus->RegisterBusObject(testObj);
/* Create the client-side endpoint */
status = g_msgBus->Connect(connectArgs.c_str());
if (ER_OK != status) {
printf("Failed to connect to \"%s\"\n", connectArgs.c_str());
exit(1);
} else {
printf("Connected to '%s'\n", connectArgs.c_str());
}
if (ER_OK == status) {
while (g_interrupt == false) {
#ifdef _WIN32
Sleep(100);
#else
usleep(100 * 1000);
#endif
}
}
} else {
printf("BusAttachment::Start failed\n");
}
/* Clean up msg bus */
if (g_msgBus) {
BusAttachment* deleteMe = g_msgBus;
g_msgBus = NULL;
delete deleteMe;
}
return (int) status;
}
示例6: main
/** Main entry point */
int main(int argc, char** argv, char** envArg)
{
QStatus status = ER_OK;
printf("AllJoyn Library version: %s\n", ajn::GetVersion());
printf("AllJoyn Library build info: %s\n", ajn::GetBuildInfo());
/* Install SIGINT handler */
signal(SIGINT, SigIntHandler);
const char* connectArgs = getenv("BUS_ADDRESS");
if (connectArgs == NULL) {
#ifdef _WIN32
connectArgs = "tcp:addr=127.0.0.1,port=9956";
#else
connectArgs = "unix:abstract=alljoyn";
#endif
}
/* Create message bus */
g_msgBus = new BusAttachment("myApp", true);
/* Add org.alljoyn.Bus.method_sample interface */
InterfaceDescription* testIntf = NULL;
status = g_msgBus->CreateInterface(INTERFACE_NAME, testIntf);
if (status == ER_OK) {
printf("Interface Created.\n");
testIntf->AddMethod("cat", "ss", "s", "inStr1,inStr2,outStr", 0);
testIntf->Activate();
} else {
printf("Failed to create interface 'org.alljoyn.Bus.method_sample'\n");
}
/* Start the msg bus */
if (ER_OK == status) {
status = g_msgBus->Start();
if (ER_OK != status) {
printf("BusAttachment::Start failed\n");
} else {
printf("BusAttachment started.\n");
}
}
/* Connect to the bus */
if (ER_OK == status) {
status = g_msgBus->Connect(connectArgs);
if (ER_OK != status) {
printf("BusAttachment::Connect(\"%s\") failed\n", connectArgs);
} else {
printf("BusAttchement connected to %s\n", connectArgs);
}
}
/* Register a bus listener in order to get discovery indications */
if (ER_OK == status) {
g_msgBus->RegisterBusListener(g_busListener);
printf("BusListener Registered.\n");
}
/* Begin discovery on the well-known name of the service to be called */
if (ER_OK == status) {
status = g_msgBus->FindAdvertisedName(SERVICE_NAME);
if (status != ER_OK) {
printf("org.alljoyn.Bus.FindAdvertisedName failed (%s))\n", QCC_StatusText(status));
}
}
/* Wait for join session to complete */
while (!s_joinComplete && !g_interrupt) {
#ifdef _WIN32
Sleep(1000);
#else
usleep(100 * 1000);
#endif
}
if (status == ER_OK && g_interrupt == false) {
ProxyBusObject remoteObj(*g_msgBus, SERVICE_NAME, SERVICE_PATH, s_sessionId);
const InterfaceDescription* alljoynTestIntf = g_msgBus->GetInterface(INTERFACE_NAME);
assert(alljoynTestIntf);
remoteObj.AddInterface(*alljoynTestIntf);
Message reply(*g_msgBus);
MsgArg inputs[2];
inputs[0].Set("s", "Hello ");
inputs[1].Set("s", "World!");
status = remoteObj.MethodCall(SERVICE_NAME, "cat", inputs, 2, reply, 5000);
if (ER_OK == status) {
printf("%s.%s ( path=%s) returned \"%s\"\n", SERVICE_NAME, "cat",
SERVICE_PATH, reply->GetArg(0)->v_string.str);
} else {
printf("MethodCall on %s.%s failed", SERVICE_NAME, "cat");
}
}
/* Deallocate bus */
if (g_msgBus) {
BusAttachment* deleteMe = g_msgBus;
//.........这里部分代码省略.........
示例7: Java_org_alljoyn_bus_samples_simpleservice_Service_startService
/*
* Class: org_alljoyn_bus_samples_simpleservice_Service
* Method: startService
* Signature: (Ljava/lang/String;Ljava/lang/String;)Z
*/
JNIEXPORT jboolean JNICALL Java_org_alljoyn_bus_samples_simpleservice_Service_startService(JNIEnv* env, jobject jobj,
jstring jServiceName, jstring packageNameStrObj)
{
QStatus status = ER_OK;
jboolean iscopy;
const char* serviceNameStr = env->GetStringUTFChars(jServiceName, &iscopy);
serviceName = "";
serviceName += SIMPLE_SERVICE_WELL_KNOWN_NAME_PREFIX;
serviceName += serviceNameStr;
SessionOpts opts(SessionOpts::TRAFFIC_MESSAGES, false, SessionOpts::PROXIMITY_ANY, TRANSPORT_ANY);
const char* daemonAddr = "unix:abstract=alljoyn";
/* Initialize AllJoyn only once */
if (!s_bus) {
const char* packageNameStr = env->GetStringUTFChars(packageNameStrObj, &iscopy);
s_bus = new BusAttachment("service", true);
/* Add org.alljoyn.samples.simple interface */
InterfaceDescription* testIntf = NULL;
status = s_bus->CreateInterface(SIMPLE_SERVICE_INTERFACE_NAME, testIntf);
if (ER_OK == status) {
testIntf->AddMethod("Ping", "s", "s", "inStr,outStr", 0);
testIntf->Activate();
} else {
LOGE("Failed to create interface %s (%s)", SIMPLE_SERVICE_INTERFACE_NAME, QCC_StatusText(status));
}
/* Start the msg bus */
if (ER_OK == status) {
status = s_bus->Start();
} else {
LOGE("BusAttachment::Start failed (%s)", QCC_StatusText(status));
}
/* Connect to the daemon */
if (ER_OK == status) {
status = s_bus->Connect(daemonAddr);
if (ER_OK != status) {
LOGE("Connect to %s failed (%s)", daemonAddr, QCC_StatusText(status));
}
}
/* Register the bus listener */
JavaVM* vm;
env->GetJavaVM(&vm);
if (ER_OK == status) {
s_busListener = new MyBusListener(vm, jobj);
s_bus->RegisterBusListener(*s_busListener);
LOGD("\n Bus Listener registered \n");
}
/* Register service object */
s_obj = new ServiceObject(*s_bus, SIMPLE_SERVICE_OBJECT_PATH, vm, jobj);
s_bus->RegisterBusObject(*s_obj);
/* Bind the session port*/
if (ER_OK == status) {
SessionPort sp = SESSION_PORT;
status = s_bus->BindSessionPort(sp, opts, *s_busListener);
if (ER_OK != status) {
LOGE("BindSessionPort failed (%s)\n", QCC_StatusText(status));
} else {
LOGD("\n Bind Session Port to %d was successful \n", SESSION_PORT);
}
}
env->ReleaseStringUTFChars(packageNameStrObj, packageNameStr);
}
/* Request name */
status = s_bus->RequestName(serviceName.c_str(), DBUS_NAME_FLAG_DO_NOT_QUEUE);
if (ER_OK != status) {
LOGE("RequestName(%s) failed (status=%s)\n", serviceName.c_str(), QCC_StatusText(status));
status = (status == ER_OK) ? ER_FAIL : status;
} else {
LOGD("\n Request Name was successful");
}
/* Advertise the name */
if (ER_OK == status) {
status = s_bus->AdvertiseName(serviceName.c_str(), opts.transports);
if (status != ER_OK) {
LOGD("Failed to advertise name %s (%s) \n", serviceName.c_str(), QCC_StatusText(status));
} else {
LOGD("\n Name %s was successfully advertised", serviceName.c_str());
}
}
env->ReleaseStringUTFChars(jServiceName, serviceNameStr);
env->DeleteLocalRef(jServiceName);
return (jboolean) true;
}
示例8: Java_org_alljoyn_bus_samples_chat_Chat_jniOnCreate
/**
* Initialize AllJoyn and connect to local daemon.
*/
JNIEXPORT jint JNICALL Java_org_alljoyn_bus_samples_chat_Chat_jniOnCreate(JNIEnv* env, jobject jobj,
jstring packageNameStrObj)
{
QStatus status = ER_OK;
const char* packageNameStr = NULL;
InterfaceDescription* chatIntf = NULL;
const char* daemonAddr = "unix:abstract=alljoyn";
JavaVM* vm;
jobject jglobalObj = NULL;
packageNameStr = env->GetStringUTFChars(packageNameStrObj, NULL);
if (!packageNameStr) {
LOGE("GetStringUTFChars failed");
status = ER_FAIL;
goto exit;
}
/* Create message bus */
s_bus = new BusAttachment(packageNameStr, true);
if (!s_bus) {
LOGE("new BusAttachment failed");
status = ER_FAIL;
goto exit;
}
/* Create org.alljoyn.bus.samples.chat interface */
status = s_bus->CreateInterface(CHAT_SERVICE_INTERFACE_NAME, chatIntf);
if (ER_OK != status) {
LOGE("Failed to create interface \"%s\" (%s)", CHAT_SERVICE_INTERFACE_NAME, QCC_StatusText(status));
goto exit;
}
status = chatIntf->AddSignal("Chat", "s", "str", 0);
if (ER_OK != status) {
LOGE("Failed to AddSignal \"Chat\" (%s)", QCC_StatusText(status));
goto exit;
}
chatIntf->Activate();
/* Start the msg bus */
status = s_bus->Start();
if (ER_OK != status) {
LOGE("BusAttachment::Start failed (%s)", QCC_StatusText(status));
goto exit;
}
/* Connect to the daemon */
status = s_bus->Connect(daemonAddr);
if (ER_OK != status) {
LOGE("BusAttachment::Connect(\"%s\") failed (%s)", daemonAddr, QCC_StatusText(status));
goto exit;
}
/* Create and register the bus object that will be used to send out signals */
if (0 != env->GetJavaVM(&vm)) {
LOGE("GetJavaVM failed");
status = ER_FAIL;
goto exit;
}
jglobalObj = env->NewGlobalRef(jobj);
if (!jglobalObj) {
LOGE("NewGlobalRef failed");
status = ER_FAIL;
goto exit;
}
s_chatObj = new ChatObject(*s_bus, CHAT_SERVICE_OBJECT_PATH, vm, jglobalObj);
if (!s_chatObj) {
LOGE("new ChatObject failed");
status = ER_FAIL;
goto exit;
}
jglobalObj = NULL; /* ChatObject owns global reference now */
status = s_bus->RegisterBusObject(*s_chatObj);
if (ER_OK != status) {
LOGE("BusAttachment::RegisterBusObject() failed (%s)", QCC_StatusText(status));
goto exit;
}
LOGD("\n Bus Object created and registered \n");
/* Register a bus listener in order to get discovery indications */
s_busListener = new MyBusListener();
if (!s_busListener) {
LOGE("new BusListener failed");
status = ER_FAIL;
goto exit;
}
s_bus->RegisterBusListener(*s_busListener);
exit:
if (ER_OK != status) {
delete s_bus;
s_bus = NULL;
delete s_chatObj;
s_chatObj = NULL;
delete s_busListener;
s_busListener = NULL;
//.........这里部分代码省略.........
示例9: BuildInterface
static QStatus BuildInterface(BusAttachment& bus)
{
QStatus status;
InterfaceDescription* intf = NULL;
status = bus.CreateInterface(INTF_NAME, intf);
QCC_ASSERT(ER_OK == status);
status = intf->AddProperty("IsOpen", "b", PROP_ACCESS_READ);
QCC_ASSERT(ER_OK == status);
status = intf->AddPropertyAnnotation("IsOpen", "org.freedesktop.DBus.Property.EmitsChangedSignal", "true");
QCC_ASSERT(ER_OK == status);
status = intf->AddProperty("Location", "s", PROP_ACCESS_READ);
QCC_ASSERT(ER_OK == status);
status = intf->AddPropertyAnnotation("Location", "org.freedesktop.DBus.Property.EmitsChangedSignal", "true");
QCC_ASSERT(ER_OK == status);
status = intf->AddProperty("KeyCode", "u", PROP_ACCESS_READ);
QCC_ASSERT(ER_OK == status);
status = intf->AddPropertyAnnotation("KeyCode", "org.freedesktop.DBus.Property.EmitsChangedSignal", "invalidates");
QCC_ASSERT(ER_OK == status);
status = intf->AddMethod("Open", "", "", "");
QCC_ASSERT(ER_OK == status);
status = intf->AddMethod("Close", "", "", "");
QCC_ASSERT(ER_OK == status);
status = intf->AddMethod("KnockAndRun", "", "", "", MEMBER_ANNOTATE_NO_REPLY);
QCC_ASSERT(ER_OK == status);
status = intf->AddMethod("GetUI", "", "s", "outStr", 0);
QCC_ASSERT(ER_OK == status);
status = intf->AddMethod("CallFunc", "s", "s", "in", 0);
QCC_ASSERT(ER_OK == status);
status = intf->AddSignal("PersonPassedThrough", "s", "name", MEMBER_ANNOTATE_SESSIONCAST);
QCC_ASSERT(ER_OK == status);
intf->Activate();
return status;
}