1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "dms_sdk_demo.h" 17 18 #include <iostream> 19 #include <string> 20 #include <vector> 21 22 using namespace OHOS; 23 using namespace DistributedSchedule; 24 using namespace std; 25 26 Business g_business; 27 namespace { 28 DmsHandler &dmsSourceHandlerdemo = DmsHandler::GetInstance(); 29 std::string g_type = "IDSchedEventListener"; 30 sptr<IDSchedEventListener> listener = sptr<IDSchedEventListener>(new Business()); 31 } 32 Register()33void Business::Register() 34 { 35 int32_t result = 0; 36 result = dmsSourceHandlerdemo.RegisterDSchedEventListener(g_type, listener); 37 if (result < 0) { 38 cout << "RegisterDSchedEventListener failed.CODE = " << result << endl; 39 } else { 40 cout << "RegisterDSchedEventListener succeed.CODE = " << result << endl; 41 } 42 } 43 UnRegister()44void Business::UnRegister() 45 { 46 int32_t result = 0; 47 result = dmsSourceHandlerdemo.UnRegisterDSchedEventListener(g_type, listener); 48 if (result < 0) { 49 cout << "UnRegisterDSchedEventListener failed.CODE = " << result << endl; 50 } else { 51 cout << "UnRegisterDSchedEventListener succeed.CODE = " << result << endl; 52 } 53 } 54 DSchedEventNotify(EventNotify & notify)55void Business::DSchedEventNotify(EventNotify& notify) 56 { 57 cout << endl << "DSchedEventNotify Start." << endl; 58 cout << "eventResult: " << notify.eventResult_ << endl; 59 cout << "srcNetworkId: " << notify.srcNetworkId_ << endl; 60 cout << "dstNetworkId: " << notify.dstNetworkId_ << endl; 61 cout << "bundleName: " << notify.bundleName_ << endl; 62 cout << "moduleName: " << notify.moduleName_ << endl; 63 cout << "abilityName: " << notify.abilityName_ << endl; 64 cout << "DSchedEventNotify Success." << endl; 65 } 66 main()67int main() 68 { 69 cout << "Please select an option to test the interface:" << endl; 70 cout << "A.RegisterDSchedEventListener B.UnRegisterDSchedEventListener X.exit" << endl; 71 cout << "\n" << endl; 72 73 char cmd; 74 while (cin >> cmd) { 75 if (cmd <= 'z' && cmd >= 'a') { 76 cmd = cmd + 'A' - 'a'; 77 } 78 switch (cmd) { 79 case 'A' : g_business.Register(); 80 break; 81 case 'B' : g_business.UnRegister(); 82 break; 83 case 'X' : g_business.UnRegister(); 84 return 0; 85 default: 86 cout << "unknown cmd, please input again" << endl; 87 } 88 } 89 90 return 0; 91 }