func (m *MockSoftcenter) sendStartMessage(pkgName string) {
	action := []interface{}{
		ActionStart,
		dbus.MakeVariant([]interface{}{pkgName, int32(0)}),
	}
	m.sendMessage([][]interface{}{action})
}
Example #2
0
func makeActionStartDetail(detail []interface{}) dbus.Variant {
	pkgName := detail[0].(string)
	operation := detail[1].(int32)
	return dbus.MakeVariant(ActionStartDetail{
		PkgName:   pkgName,
		Operation: operation,
	})
}
Example #3
0
func makeActionFinishDetail(detail []interface{}) dbus.Variant {
	pkgName := detail[0].(string)
	operation := detail[1].(int32)
	return dbus.MakeVariant(ActionFinishDetail{
		PkgName:   pkgName,
		Operation: operation,
		Pkgs:      makePkgInfoList(detail[2]),
	})
}
Example #4
0
func doSetSettingKey(data connectionData, section, key string, value interface{}) {
	var sectionData map[string]dbus.Variant
	sectionData, ok := data[section]
	if !ok {
		logger.Errorf(`set connection data failed, section "%s" is not exits yet`, section)
		return
	}
	sectionData[key] = dbus.MakeVariant(value)
	logger.Debugf("setSettingKey: data[%s][%s]=%#v", section, key, value)
}
Example #5
0
func makeActionUpdateDetail(detail []interface{}) dbus.Variant {
	pkgName := detail[0].(string)
	operation := detail[1].(int32)
	process := detail[2].(int32)
	description := detail[3].(string)
	return dbus.MakeVariant(ActionUpdateDetail{
		PkgName:     pkgName,
		Operation:   operation,
		Process:     process,
		Description: description,
	})
}
Example #6
0
func polkitAuthWithPid(actionId string, pid uint32) (bool, error) {
	polkit, err := policykit1.NewAuthority(polkitSender,
		polkitPath)
	if err != nil {
		return false, err
	}

	var subject polkitSubject
	subject.SubjectKind = "unix-process"
	subject.SubjectDetails = make(map[string]dbus.Variant)
	subject.SubjectDetails["pid"] = dbus.MakeVariant(uint32(pid))
	subject.SubjectDetails["start-time"] = dbus.MakeVariant(uint64(0))

	var details = make(map[string]string)
	details[""] = ""
	var flg uint32 = 1
	var cancelId string

	ret, err := polkit.CheckAuthorization(subject,
		actionId, details, flg, cancelId)
	if err != nil {
		return false, err
	}

	//If ret[0].(bool) == true, successful.
	if len(ret) == 0 {
		return false, fmt.Errorf("No results returned")
	}

	v, ok := ret[0].(bool)
	if !ok {
		return false, fmt.Errorf("Invalid result type")
	}

	return v, nil
}
func (m *MockSoftcenter) sendUpdateMessage(pkgName string) {
	updateTime := rand.Intn(5) + 1
	for i := 0; i < updateTime; i++ {
		action := []interface{}{
			ActionUpdate,
			dbus.MakeVariant([]interface{}{
				pkgName,
				int32(1),
				int32(int(i+1) / updateTime),
				"update",
			}),
		}
		m.sendMessage([][]interface{}{action})
		time.Sleep(time.Duration(rand.Int31n(100)+100) * time.Millisecond)
	}
}
func (m *MockSoftcenter) sendFinishedMessage(pkgName string) {
	action := []interface{}{
		ActionFinish,
		dbus.MakeVariant([]interface{}{
			pkgName,
			int32(2),
			[][]interface{}{
				[]interface{}{
					pkgName,
					true,
					false,
					false,
				},
			},
		}),
	}
	m.sendMessage([][]interface{}{action})
}
func (m *MockSoftcenter) sendFailedMessage(pkgName string) {
	action := []interface{}{
		ActionFailed,
		dbus.MakeVariant([]interface{}{
			pkgName,
			int32(3),
			[][]interface{}{
				[]interface{}{
					pkgName,
					false,
					false,
					false,
				},
			},
			"uninstall failed",
		}),
	}
	m.sendMessage([][]interface{}{action})
}
Example #10
0
func (*testWrapper) TestGetDBusObjectValueInt16(c *C.C) {
	data := make(dbusObjectData)
	c.Check(getDBusObjectValueInt16(data, "key"), C.Equals, int16(0))
	data["key"] = dbus.MakeVariant(int16(8))
	c.Check(getDBusObjectValueInt16(data, "key"), C.Equals, int16(8))
}
Example #11
0
func (*testWrapper) TestGetDBusObjectValueString(c *C.C) {
	data := make(dbusObjectData)
	c.Check(getDBusObjectValueString(data, "key"), C.Equals, "")
	data["key"] = dbus.MakeVariant("value")
	c.Check(getDBusObjectValueString(data, "key"), C.Equals, "value")
}
Example #12
0
func (*testWrapper) TestIsDBusObjectKeyExists(c *C.C) {
	data := make(dbusObjectData)
	c.Check(isDBusObjectKeyExists(data, "key"), C.Equals, false)
	data["key"] = dbus.MakeVariant(int32(8))
	c.Check(isDBusObjectKeyExists(data, "key"), C.Equals, true)
}