-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ac1658
commit 627ad0c
Showing
8 changed files
with
839 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.PHONY: help default clean gbserver | ||
|
||
default: gbserver | ||
|
||
clean: | ||
rm -f ./objs/gbserver | ||
|
||
gbserver: ./objs/gbserver | ||
|
||
./objs/gbserver: | ||
go build -o objs/gbserver . | ||
|
||
help: | ||
@echo "Usage: make [gbserver]" | ||
@echo " gbserver Make the gbserver to ./objs/gbserver" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package gbserver | ||
|
||
import "sync" | ||
|
||
type ChannelInfo struct { | ||
DeviceID string // 通道ID | ||
ParentID string | ||
Name string | ||
Manufacturer string | ||
Model string | ||
Owner string | ||
CivilCode string | ||
Address string | ||
Port int | ||
Parental int | ||
SafetyWay int | ||
RegisterWay int | ||
Secrecy int | ||
Status ChannelStatus | ||
} | ||
|
||
type ChannelStatus string | ||
|
||
type DeviceInfo struct { | ||
DeviceID string | ||
SourceAddr string | ||
ChannelList []ChannelInfo | ||
} | ||
|
||
var Devices sync.Map | ||
|
||
func (s *GB28181Server) AddDevice(id string, sourceAddr string) { | ||
Devices.Store(id, DeviceInfo{ | ||
DeviceID: id, | ||
SourceAddr: sourceAddr, | ||
}) | ||
} | ||
|
||
func (s *GB28181Server) RemoveDevice(id string) { | ||
Devices.Delete(id) | ||
} | ||
|
||
func (s *GB28181Server) GetDevice(id string) (DeviceInfo, bool) { | ||
v, ok := Devices.Load(id) | ||
if !ok { | ||
return DeviceInfo{}, false | ||
} | ||
return v.(DeviceInfo), true | ||
} | ||
|
||
func (s *GB28181Server) UpdateChannels(list ...ChannelInfo) { | ||
for _, channel := range list { | ||
if info, ok := s.GetDevice(channel.ParentID); ok { | ||
info.ChannelList = append(info.ChannelList, channel) | ||
Devices.Store(channel.DeviceID, info) | ||
} | ||
} | ||
} | ||
|
||
func (s *GB28181Server) GetDeviceByChannel(channelID string) (DeviceInfo, bool) { | ||
var result DeviceInfo | ||
Devices.Range(func(key, value interface{}) bool { | ||
info := value.(DeviceInfo) | ||
for _, channel := range info.ChannelList { | ||
if channel.DeviceID == channelID { | ||
result = info | ||
return false | ||
} | ||
} | ||
return true | ||
}) | ||
return result, result.DeviceID != "" | ||
} |
Oops, something went wrong.