当前位置: 首页>>代码示例>>C++>>正文


C++ sp::getBinder方法代码示例

本文整理汇总了C++中sp::getBinder方法的典型用法代码示例。如果您正苦于以下问题:C++ sp::getBinder方法的具体用法?C++ sp::getBinder怎么用?C++ sp::getBinder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sp的用法示例。


在下文中一共展示了sp::getBinder方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: switch

void Process::Stub::onTransact(int32_t what, int32_t arg1, int32_t arg2, const sp<Object>& obj, const sp<Bundle>& data, const sp<Object>& result) {
    switch (what) {
    case MSG_CREATE_SERVICE: {
        sp<Intent> intent = object_cast<Intent>(data->getObject("intent"));
        sp<IBinder> binder = data->getBinder("binder");
        createService(intent, RemoteCallback::Stub::asInterface(binder));
        break;
    }
    case MSG_START_SERVICE: {
        sp<Intent> intent = object_cast<Intent>(data->getObject("intent"));
        int32_t flags = arg1;
        int32_t startId = arg2;
        sp<IBinder> binder = data->getBinder("binder");
        startService(intent, flags, startId, RemoteCallback::Stub::asInterface(binder));
        break;
    }
    case MSG_STOP_SERVICE: {
        sp<Intent> intent = object_cast<Intent>(data->getObject("intent"));
        sp<IBinder> binder = data->getBinder("binder");
        if (binder == nullptr) {
            stopService(intent);
        } else {
            stopService(intent, RemoteCallback::Stub::asInterface(binder));
        }
        break;
    }
    case MSG_BIND_SERVICE: {
        sp<Intent> intent = object_cast<Intent>(data->getObject("intent"));
        sp<ServiceConnection> conn = object_cast<ServiceConnection>(data->getObject("conn"));
        int32_t flags = data->getInt("flags");
        sp<IBinder> binder = data->getBinder("binder");
        bindService(intent, conn, flags, RemoteCallback::Stub::asInterface(binder));
        break;
    }
    case MSG_UNBIND_SERVICE: {
        sp<Intent> intent = object_cast<Intent>(data->getObject("intent"));
        sp<IBinder> binder = data->getBinder("binder");
        if (binder == nullptr) {
            unbindService(intent);
        } else {
            unbindService(intent, RemoteCallback::Stub::asInterface(binder));
        }
        break;
    }
    default:
        Binder::onTransact(what, arg1, arg2, obj, data, result);
        break;
    }
}
开发者ID:,项目名称:,代码行数:49,代码来源:

示例2: onResult

            void onResult(const sp<Bundle>& data) {
                sp<ContextImpl> context = mContext.get();
                if (context != nullptr) {
                    bool result = data->getBoolean("result");
                    if (result) {
                        sp<IBinder> binder = data->getBinder("binder");
                        mConn->onServiceConnected(mService->getComponent(), binder);
                    } else {
                        Log::e(ContextImpl::TAG, "Cannot bind to service %s", mService->getComponent()->toShortString()->c_str());
                    }

                    context->mServiceConnectionCallbacks->remove(getCallback());
                }
            }
开发者ID:Himmele,项目名称:Mindroid.cpp,代码行数:14,代码来源:ContextImpl.cpp

示例3: switch

void ServiceManager::Stub::onTransact(int32_t what, int32_t arg1, int32_t arg2,
                                      const sp<Object>& obj, const sp<Bundle>& data, const sp<Object>& result)
{
    switch (what) {
    case MSG_START_SERVICE: {
            auto promise = object_cast<Promise<sp<ComponentName>>>(result);
            sp<Intent> service = object_cast<Intent>(obj);
            sp<ComponentName> component = startService(service);
            promise->set(component);
            break;
        }

    case MSG_STOP_SERVICE: {
            auto promise = object_cast<Promise<bool>>(result);
            sp<Intent> service = object_cast<Intent>(obj);
            promise->set(stopService(service));
            break;
        }

    case MSG_BIND_SERVICE: {
            auto promise = object_cast<Promise<bool>>(result);
            sp<Intent> service = object_cast<Intent>(data->getObject("intent"));
            sp<ServiceConnection> conn = object_cast<ServiceConnection>
                                         (data->getObject("conn"));
            int32_t flags = data->getInt("flags");
            sp<IBinder> binder = data->getBinder("binder");
            promise->set(bindService(service, conn, flags,
                                     binder::RemoteCallback::Stub::asInterface(binder)));
            break;
        }

    case MSG_UNBIND_SERVICE: {
            sp<Intent> intent = object_cast<Intent>(data->getObject("intent"));
            sp<ServiceConnection> conn = object_cast<ServiceConnection>
                                         (data->getObject("conn"));
            sp<IBinder> binder = nullptr;

            if (binder == nullptr) {
                unbindService(intent, conn);
            } else {
                unbindService(intent, conn, binder::RemoteCallback::Stub::asInterface(binder));
            }

            break;
        }

    case MSG_START_SYSTEM_SERVICE: {
            auto promise = object_cast<Promise<sp<ComponentName>>>(result);
            sp<Intent> service = object_cast<Intent>(obj);
            sp<ComponentName> component = startSystemService(service);
            promise->set(component);
            break;
        }

    case MSG_STOP_SYSTEM_SERVICE: {
            auto promise = object_cast<Promise<bool>>(result);
            sp<Intent> service = object_cast<Intent>(obj);
            promise->set(stopSystemService(service));
            break;
        }

    default:
        Binder::onTransact(what, arg1, arg2, obj, data, result);
    }
}
开发者ID:jasonblog,项目名称:note,代码行数:65,代码来源:IServiceManager.cpp


注:本文中的sp::getBinder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。