Skip to content

Commit

Permalink
enh: reduce cyclomatic complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
huskar-t committed Sep 3, 2024
1 parent 84489e4 commit 9b5d6f8
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions opcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,9 @@ func Connect(progID, node string) (opcServer *OPCServer, err error) {
if !com.IsLocal(node) {
location = com.CLSCTX_REMOTE_SERVER
}
var clsid *windows.GUID
if location == com.CLSCTX_LOCAL_SERVER {
id, err := windows.GUIDFromString(progID)
if err != nil {
return nil, NewOPCWrapperError("windows.GUIDFromString", err)
}
clsid = &id
} else {
// try get clsid from server list
clsid, err = getClsIDFromServerList(progID, node, location)
if err != nil {
// try get clsid from windows reg
clsid, err = getClsIDFromReg(progID, node)
if err != nil {
return nil, NewOPCWrapperError("getClsIDFromReg", err)
}
}
clsid, err := getClsID(progID, node, location)
if err != nil {
return nil, NewOPCWrapperError("get clsid", err)
}
iUnknownServer, err := com.MakeCOMObjectEx(node, location, clsid, &com.IID_IOPCServer)
if err != nil {
Expand Down Expand Up @@ -126,6 +112,27 @@ func Connect(progID, node string) (opcServer *OPCServer, err error) {
return opcServer, nil
}

func getClsID(progID, node string, location com.CLSCTX) (clsid *windows.GUID, err error) {
if location == com.CLSCTX_LOCAL_SERVER {
id, err := windows.GUIDFromString(progID)
if err != nil {
return nil, NewOPCWrapperError("windows.GUIDFromString", err)
}
return &id, nil
} else {
// try get clsid from server list
clsid, err = getClsIDFromServerList(progID, node, location)
if err != nil {
// try get clsid from windows reg
clsid, err = getClsIDFromReg(progID, node)
if err != nil {
return nil, NewOPCWrapperError("getClsIDFromReg", err)
}
}
return clsid, nil
}
}

func getClsIDFromServerList(progID, node string, location com.CLSCTX) (*windows.GUID, error) {
iCatInfo, err := com.MakeCOMObjectEx(node, location, &com.CLSID_OpcServerList, &com.IID_IOPCServerList2)
if err != nil {
Expand Down

0 comments on commit 9b5d6f8

Please sign in to comment.