0

0

错误 org.freedesktop.DBus.Error.UnknownMethod:未知/无效方法“Notify”

PHPz

PHPz

发布时间:2024-02-06 08:00:17

|

1861人浏览过

|

来源于stackoverflow

转载

错误 org.freedesktop.dbus.error.unknownmethod:未知/无效方法“notify”

问题内容

我正在尝试使用 godbus 创建一个通知服务器,但我无法正确地将我的服务器对象导出到 dbus,并且 dbus 只能识别我的内省 xml。我按照 https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html 来实现它。我还在 godbus 存储库中使用了 _example/server.go,您可能会在下面提供的服务器代码中注意到。 这是服务器代码:

package main

import (
    "fmt"
    "os"

    "github.com/godbus/dbus/v5"
    "github.com/godbus/dbus/v5/introspect"
)

const xml = `

    
        
            
            
            
            
            
            
            
            
            
        

        
            
        

        
            
            
            
            
        

        
            
        

        
            
            
        
    ` + introspect.introspectdatastring + ` `

type notificationserver struct {
}

func (s *notificationserver) notify(appname string, replacesid uint32, appicon string, summary string, body string, actions []string, hints map[string]dbus.variant, expiretimeout int32) (uint32, *dbus.error) {
    fmt.printf("new notification: %s\n", body)
    return 0, nil
}

func (s *notificationserver) getcapabilities() ([]string, *dbus.error) {
    return []string{"action-icons", "actions", "body", "body-hyperlinks", "body-images", "body-markup", "icon-multi", "icon-static", "persistence", "sound"}, nil
}

func (s *notificationserver) getserverinformation() (string, string, string, string, *dbus.error) {
    return "antarctica", "antarctica.com", "1.0", "1.2", nil
}

func (s *notificationserver) closenotification(id uint32) *dbus.error {
    s.notificationclosed(id, 0)
    return nil
}
func (s *notificationserver) notificationclosed(id, reason uint32) {

}

func main() {
    conn, err := dbus.connectsessionbus()
    if err != nil {
        panic(err)
    }
    defer conn.close()

    reply, err := conn.requestname("com.antarctica.notification",
        dbus.nameflagdonotqueue)
    if err != nil {
        panic(err)
    }

    if reply != dbus.requestnamereplyprimaryowner {
        fmt.fprintln(os.stderr, "name already taken")
        os.exit(1)
    }
    server := notificationserver{}
    err = conn.export(server,"/org/freedesktop/notifications","org.freedesktop.notifications")
    if err != nil {
        panic(err)
    }
    conn.export(introspect.introspectable(xml), "/org/freedesktop/notifications", "org.freedesktop.dbus.introspectable")
    fmt.println("listening on com.antarctica.notification / /com/antarctica/notification ...")
    select {}
}

现在的问题是,即使客户端可以访问内省 xml:

$ gdbus introspect --session --dest com.antarctica.notification --object-path /org/freedesktop/notifications --xml

> returns xml

我无法使用我在服务器代码中编写的 org.freedesktop.notifications 方法。例如,notify 未知/无效,这对于每种方法都是相同的:

$ dbus-send --session --print-reply=literal --dest=com.antarctica.notification /org/freedesktop/Notifications org.freedesktop.Notifications.Notify

> Error org.freedesktop.DBus.Error.UnknownMethod: Unknown / invalid method 'Notify'

也在 qdbusviewer 中,当我尝试执行任何方法时,它显示“无法在接口 org.freedesktop.notifications 中的路径 /org/freedesktop/notifications 上找到方法 x”

我尝试过的:

Moshi Chat
Moshi Chat

法国AI实验室Kyutai推出的端到端实时多模态AI语音模型,具备听、说、看的能力,不仅可以实时收听,还能进行自然对话。

下载
  1. 检查 dbus 是否正在运行
  2. 检查我的服务器是否正在运行
  3. 我也尝试重新启动 dbus 服务和我的计算机
  4. 我认为notificationserver实例(服务器)根本没有被导出,但我不知道为什么

正确答案


这有效。你犯了两个错误:

  1. com.antarctica.notification
  2. func (s *notificationserver)

您必须请求“org.freedesktop.notifications”作为名称,并且不能在函数中使用指针。

  1. org.freedesktop.notifications
  2. func(通知服务器)
  3. (你也不需要内省)
package main

import (
    "fmt"
    "os"

    "github.com/godbus/dbus/v5"
)

type notificationServer struct{}

func (s notificationServer) Notify(appName string, replacesID uint32, appIcon string, summary string, body string, actions []string, hints map[string]dbus.Variant, expireTimeout int32) (uint32, *dbus.Error) {
    fmt.Printf("New notification: %s\n", body)
    return 0, nil
}

func (s notificationServer) GetCapabilities() ([]string, *dbus.Error) {
    return []string{"action-icons", "actions", "body", "body-hyperlinks", "body-images", "body-markup", "icon-multi", "icon-static", "persistence", "sound"}, nil
}

func (s notificationServer) GetServerInformation() (string, string, string, string, *dbus.Error) {
    return "antarctica", "antarctica.com", "1.0", "1.2", nil
}

func main() {
    conn, err := dbus.ConnectSessionBus()
    if err != nil {
        panic(err)
    }
    defer conn.Close()

    f := notificationServer{}
    conn.Export(f, "/org/freedesktop/Notifications", "org.freedesktop.Notifications")

    reply, err := conn.RequestName("org.freedesktop.Notifications", dbus.NameFlagDoNotQueue)
    if err != nil {
        panic(err)
    }
    if reply != dbus.RequestNameReplyPrimaryOwner {
        fmt.Fprintln(os.Stderr, "name already taken")
        os.Exit(1)
    }
    fmt.Println("Listening...")
    select {}
}

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
html版权符号
html版权符号

html版权符号是“©”,可以在html源文件中直接输入或者从word中复制粘贴过来,php中文网还为大家带来html的相关下载资源、相关课程以及相关文章等内容,供大家免费下载使用。

593

2023.06.14

html在线编辑器
html在线编辑器

html在线编辑器是用于在线编辑的工具,编辑的内容是基于HTML的文档。它经常被应用于留言板留言、论坛发贴、Blog编写日志或等需要用户输入普通HTML的地方,是Web应用的常用模块之一。php中文网为大家带来了html在线编辑器的相关教程、以及相关文章等内容,供大家免费下载使用。

638

2023.06.21

html网页制作
html网页制作

html网页制作是指使用超文本标记语言来设计和创建网页的过程,html是一种标记语言,它使用标记来描述文档结构和语义,并定义了网页中的各种元素和内容的呈现方式。本专题为大家提供html网页制作的相关的文章、下载、课程内容,供大家免费下载体验。

458

2023.07.31

html空格
html空格

html空格是一种用于在网页中添加间隔和对齐文本的特殊字符,被用于在网页中插入额外的空间,以改变元素之间的排列和对齐方式。本专题为大家提供html空格的相关的文章、下载、课程内容,供大家免费下载体验。

241

2023.08.01

html是什么
html是什么

HTML是一种标准标记语言,用于创建和呈现网页的结构和内容,是互联网发展的基石,为网页开发提供了丰富的功能和灵活性。本专题为大家提供html相关的各种文章、以及下载和课程。

2856

2023.08.11

html字体大小怎么设置
html字体大小怎么设置

在网页设计中,字体大小的选择是至关重要的。合理的字体大小不仅可以提升网页的可读性,还能够影响用户对网页整体布局的感知。php中文网将介绍一些常用的方法和技巧,帮助您在HTML中设置合适的字体大小。

500

2023.08.11

html转txt
html转txt

html转txt的方法有使用文本编辑器、使用在线转换工具和使用Python编程。本专题为大家提供html转txt相关的文章、下载、课程内容,供大家免费下载体验。

306

2023.08.31

html文本框代码怎么写
html文本框代码怎么写

html文本框代码:1、单行文本框【<input type="text" style="height:..;width:..;" />】;2、多行文本框【textarea style=";height:;"></textare】。

419

2023.09.01

php源码安装教程大全
php源码安装教程大全

本专题整合了php源码安装教程,阅读专题下面的文章了解更多详细内容。

7

2025.12.31

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号