1686862fbSopenharmony_ci/* 2686862fbSopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3686862fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4686862fbSopenharmony_ci * you may not use this file except in compliance with the License. 5686862fbSopenharmony_ci * You may obtain a copy of the License at 6686862fbSopenharmony_ci * 7686862fbSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8686862fbSopenharmony_ci * 9686862fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10686862fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11686862fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12686862fbSopenharmony_ci * See the License for the specific language governing permissions and 13686862fbSopenharmony_ci * limitations under the License. 14686862fbSopenharmony_ci */ 15686862fbSopenharmony_ci 16686862fbSopenharmony_ci#include "dms_sdk_demo.h" 17686862fbSopenharmony_ci 18686862fbSopenharmony_ci#include <iostream> 19686862fbSopenharmony_ci#include <string> 20686862fbSopenharmony_ci#include <vector> 21686862fbSopenharmony_ci 22686862fbSopenharmony_ciusing namespace OHOS; 23686862fbSopenharmony_ciusing namespace DistributedSchedule; 24686862fbSopenharmony_ciusing namespace std; 25686862fbSopenharmony_ci 26686862fbSopenharmony_ciBusiness g_business; 27686862fbSopenharmony_cinamespace { 28686862fbSopenharmony_ciDmsHandler &dmsSourceHandlerdemo = DmsHandler::GetInstance(); 29686862fbSopenharmony_cisptr<IDSchedEventListener> listener = sptr<IDSchedEventListener>(new Business()); 30686862fbSopenharmony_ciContinueInfo g_continueInfo; 31686862fbSopenharmony_ci} 32686862fbSopenharmony_ci 33686862fbSopenharmony_civoid Business::Register(DSchedEventType type) 34686862fbSopenharmony_ci{ 35686862fbSopenharmony_ci int32_t result = 0; 36686862fbSopenharmony_ci result = dmsSourceHandlerdemo.RegisterDSchedEventListener(type, listener); 37686862fbSopenharmony_ci if (result < 0) { 38686862fbSopenharmony_ci cout << "RegisterDSchedEventListener failed.CODE = " << result << endl; 39686862fbSopenharmony_ci } else { 40686862fbSopenharmony_ci cout << "RegisterDSchedEventListener succeed.CODE = " << result << endl; 41686862fbSopenharmony_ci } 42686862fbSopenharmony_ci} 43686862fbSopenharmony_ci 44686862fbSopenharmony_civoid Business::UnRegister(DSchedEventType type) 45686862fbSopenharmony_ci{ 46686862fbSopenharmony_ci int32_t result = 0; 47686862fbSopenharmony_ci result = dmsSourceHandlerdemo.UnRegisterDSchedEventListener(type, listener); 48686862fbSopenharmony_ci if (result < 0) { 49686862fbSopenharmony_ci cout << "UnRegisterDSchedEventListener failed.CODE = " << result << endl; 50686862fbSopenharmony_ci } else { 51686862fbSopenharmony_ci cout << "UnRegisterDSchedEventListener succeed.CODE = " << result << endl; 52686862fbSopenharmony_ci } 53686862fbSopenharmony_ci} 54686862fbSopenharmony_ci 55686862fbSopenharmony_civoid Business::GetContinueDeviceInfo() 56686862fbSopenharmony_ci{ 57686862fbSopenharmony_ci int32_t result = 0; 58686862fbSopenharmony_ci result = dmsSourceHandlerdemo.GetContinueInfo(g_continueInfo); 59686862fbSopenharmony_ci if (result < 0) { 60686862fbSopenharmony_ci cout << "GetContinueInfo failed.CODE = " << result << endl; 61686862fbSopenharmony_ci } else { 62686862fbSopenharmony_ci cout << "continueInfo.dstNetworkId_ : " << g_continueInfo.dstNetworkId_ << endl; 63686862fbSopenharmony_ci cout << "continueInfo.srcNetworkId_ : " << g_continueInfo.srcNetworkId_ << endl; 64686862fbSopenharmony_ci } 65686862fbSopenharmony_ci} 66686862fbSopenharmony_ci 67686862fbSopenharmony_civoid Business::GetDSchedEventInfo(DSchedEventType type) 68686862fbSopenharmony_ci{ 69686862fbSopenharmony_ci vector<EventNotify> notifys; 70686862fbSopenharmony_ci int32_t result = dmsSourceHandlerdemo.GetDSchedEventInfo(type, notifys); 71686862fbSopenharmony_ci if (result < 0) { 72686862fbSopenharmony_ci cout << "GetContinueInfo failed.CODE = " << result << endl; 73686862fbSopenharmony_ci } else { 74686862fbSopenharmony_ci for (auto notify : notifys) { 75686862fbSopenharmony_ci cout << endl << "DSchedEventInfo:" << endl; 76686862fbSopenharmony_ci cout << "eventResult: " << notify.eventResult_ << endl; 77686862fbSopenharmony_ci cout << "srcNetworkId: " << notify.srcNetworkId_ << endl; 78686862fbSopenharmony_ci cout << "dstNetworkId: " << notify.dstNetworkId_ << endl; 79686862fbSopenharmony_ci cout << "srcBundleName: " << notify.srcBundleName_ << endl; 80686862fbSopenharmony_ci cout << "srcModuleName: " << notify.srcModuleName_ << endl; 81686862fbSopenharmony_ci cout << "srcAbilityName: " << notify.srcAbilityName_ << endl; 82686862fbSopenharmony_ci cout << "destBundleName: " << notify.destBundleName_ << endl; 83686862fbSopenharmony_ci cout << "destModuleName: " << notify.destModuleName_ << endl; 84686862fbSopenharmony_ci cout << "destAbilityName: " << notify.destAbilityName_ << endl; 85686862fbSopenharmony_ci cout << "developerId: " << notify.developerId_ << endl; 86686862fbSopenharmony_ci cout << "dSchedEventType: " << notify.dSchedEventType_ << endl; 87686862fbSopenharmony_ci cout << "state: " << notify.state_ << endl << endl; 88686862fbSopenharmony_ci } 89686862fbSopenharmony_ci } 90686862fbSopenharmony_ci notifys.clear(); 91686862fbSopenharmony_ci} 92686862fbSopenharmony_ci 93686862fbSopenharmony_civoid Business::DSchedEventNotify(EventNotify& notify) 94686862fbSopenharmony_ci{ 95686862fbSopenharmony_ci cout << endl << "DSchedEventNotify Start." << endl; 96686862fbSopenharmony_ci cout << "eventResult: " << notify.eventResult_ << endl; 97686862fbSopenharmony_ci cout << "srcNetworkId: " << notify.srcNetworkId_ << endl; 98686862fbSopenharmony_ci cout << "dstNetworkId: " << notify.dstNetworkId_ << endl; 99686862fbSopenharmony_ci cout << "srcBundleName: " << notify.srcBundleName_ << endl; 100686862fbSopenharmony_ci cout << "srcModuleName: " << notify.srcModuleName_ << endl; 101686862fbSopenharmony_ci cout << "srcAbilityName: " << notify.srcAbilityName_ << endl; 102686862fbSopenharmony_ci cout << "destBundleName: " << notify.destBundleName_ << endl; 103686862fbSopenharmony_ci cout << "destModuleName: " << notify.destModuleName_ << endl; 104686862fbSopenharmony_ci cout << "destAbilityName: " << notify.destAbilityName_ << endl; 105686862fbSopenharmony_ci cout << "developerId: " << notify.developerId_ << endl; 106686862fbSopenharmony_ci cout << "dSchedEventType: " << notify.dSchedEventType_ << endl; 107686862fbSopenharmony_ci cout << "state: " << notify.state_ << endl; 108686862fbSopenharmony_ci cout << "DSchedEventNotify Success." << endl; 109686862fbSopenharmony_ci} 110686862fbSopenharmony_ciint main() 111686862fbSopenharmony_ci{ 112686862fbSopenharmony_ci cout << "Please select an option to test the interface:" << endl; 113686862fbSopenharmony_ci cout << "A.RegisterContinueListener B.UnRegisterContinueListener C.GetContinueInfo" << endl; 114686862fbSopenharmony_ci cout << "D.RegisterCollaborationListener E.UnRegisterCollaborationListener F.GetCollaborationInfo" << endl; 115686862fbSopenharmony_ci cout << "G.RegisterAllListener H.UnRegisterAllListener I.GetAllInfo" << endl; 116686862fbSopenharmony_ci cout << "J.GetContinueDeviceInfo X.exit" << endl; 117686862fbSopenharmony_ci cout << "\n" << endl; 118686862fbSopenharmony_ci 119686862fbSopenharmony_ci char cmd; 120686862fbSopenharmony_ci while (cin >> cmd) { 121686862fbSopenharmony_ci if (cmd <= 'z' && cmd >= 'a') { 122686862fbSopenharmony_ci cmd = cmd + 'A' - 'a'; 123686862fbSopenharmony_ci } 124686862fbSopenharmony_ci switch (cmd) { 125686862fbSopenharmony_ci case 'A' : g_business.Register(DMS_CONTINUE); 126686862fbSopenharmony_ci break; 127686862fbSopenharmony_ci case 'B' : g_business.UnRegister(DMS_CONTINUE); 128686862fbSopenharmony_ci break; 129686862fbSopenharmony_ci case 'C' : g_business.GetDSchedEventInfo(DMS_CONTINUE); 130686862fbSopenharmony_ci break; 131686862fbSopenharmony_ci case 'D' : g_business.Register(DMS_COLLABORATION); 132686862fbSopenharmony_ci break; 133686862fbSopenharmony_ci case 'E' : g_business.UnRegister(DMS_COLLABORATION); 134686862fbSopenharmony_ci break; 135686862fbSopenharmony_ci case 'F' : g_business.GetDSchedEventInfo(DMS_COLLABORATION); 136686862fbSopenharmony_ci break; 137686862fbSopenharmony_ci case 'G' : g_business.Register(DMS_ALL); 138686862fbSopenharmony_ci break; 139686862fbSopenharmony_ci case 'H' : g_business.UnRegister(DMS_ALL); 140686862fbSopenharmony_ci break; 141686862fbSopenharmony_ci case 'I' : g_business.GetDSchedEventInfo(DMS_ALL); 142686862fbSopenharmony_ci break; 143686862fbSopenharmony_ci case 'J' : g_business.GetContinueDeviceInfo(); 144686862fbSopenharmony_ci break; 145686862fbSopenharmony_ci case 'X' : 146686862fbSopenharmony_ci return 0; 147686862fbSopenharmony_ci default: 148686862fbSopenharmony_ci cout << "unknown cmd, please input again" << endl; 149686862fbSopenharmony_ci } 150686862fbSopenharmony_ci } 151686862fbSopenharmony_ci 152686862fbSopenharmony_ci return 0; 153686862fbSopenharmony_ci}